-
Notifications
You must be signed in to change notification settings - Fork 390
/
test_forwarding_class.cc
154 lines (119 loc) · 3.58 KB
/
test_forwarding_class.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include <sys/socket.h>
#include <net/if.h>
#ifdef __linux__
#include <linux/netlink.h>
#include <linux/if_tun.h>
#include <linux/if_packet.h>
#endif
#ifdef __FreeBSD__
#include <sys/sockio.h>
#include <ifaddrs.h>
#endif
#include "testing/gunit.h"
#include <base/logging.h>
#include <io/event_manager.h>
#include <tbb/task.h>
#include <base/task.h>
#include <cmn/agent_cmn.h>
#include "oper/operdb_init.h"
#include "controller/controller_init.h"
#include "pkt/pkt_init.h"
#include "services/services_init.h"
#include "vrouter/ksync/ksync_init.h"
#include "oper/interface_common.h"
#include "test_cmn_util.h"
#include "vr_types.h"
#include <controller/controller_export.h>
#include <ksync/ksync_sock_user.h>
#include <boost/assign/list_of.hpp>
#include "oper/qos_config.h"
using namespace boost::assign;
void RouterIdDepInit(Agent *agent) {
}
class FwdClassTest : public ::testing::Test {
virtual void SetUp() {
agent = Agent::GetInstance();
}
virtual void TearDown() {
}
protected:
Agent *agent;
};
TEST_F(FwdClassTest, Test1) {
AddGlobalConfig(NULL, 0);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 0);
}
TEST_F(FwdClassTest, Test2) {
TestForwardingClassData data[] = {
{1, 1, 1, 1, 1},
{2, 2, 2, 2, 2}
};
AddGlobalConfig(data, 2);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 2);
VerifyForwardingClass(agent, data, 2);
DelGlobalConfig(data, 2);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 0);
}
TEST_F(FwdClassTest, Test3) {
TestForwardingClassData data[] = {
{1, 1, 1, 1, 1},
{2, 2, 2, 2, 2}
};
AddGlobalConfig(data, 2);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 2);
VerifyForwardingClass(agent, data, 2);
TestForwardingClassData data2[] = {
{1, 2, 3, 4, 5},
{2, 3, 4, 5, 6}
};
AddGlobalConfig(data2, 2);
DelLink("forwarding-class", "fc1", "qos-queue", "qosqueue1");
DelLink("forwarding-class", "fc2", "qos-queue", "qosqueue2");
DelNode("qos-queue", "qosqueue1");
DelNode("qos-queue", "qosqueue2");
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 2);
VerifyForwardingClass(agent, data2, 2);
DelGlobalConfig(data2, 2);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 0);
}
TEST_F(FwdClassTest, Test4) {
TestForwardingClassData data[] = {
{1, 1, 1, 1, 1},
};
Agent::GetInstance()->params()->add_nic_queue(10, 100);
AddGlobalConfig(data, 1);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 1);
VerifyForwardingClass(agent, data, 1);
ForwardingClassKey key(MakeUuid(data[0].id_));
ForwardingClass *fc = static_cast<ForwardingClass *>(
agent->forwarding_class_table()->FindActiveEntry(&key));
EXPECT_TRUE(fc->nic_queue_id() == Agent::kInvalidQueueId);
AddQosQueue("qosqueue1", 1, 10);
client->WaitForIdle();
EXPECT_TRUE(fc->nic_queue_id() == 100);
DelGlobalConfig(data, 1);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 0);
}
int main(int argc, char **argv) {
GETUSERARGS();
client = TestInit(init_file, ksync_init, false, false, false);
int ret = RUN_ALL_TESTS();
usleep(10000);
client->WaitForIdle();
usleep(10000);
TestShutdown();
delete client;
return ret;
}