/
test_bgp_service.cc
152 lines (131 loc) · 4.63 KB
/
test_bgp_service.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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include "test/test_cmn_util.h"
#include "test_pkt_util.h"
#include "pkt/flow_proto.h"
#include "pkt/flow_mgmt.h"
#include <base/task.h>
#include <base/test/task_test_util.h>
VmInterface *vnet[16];
InetInterface *vhost;
char vhost_addr[32];
char vnet_addr[16][32];
PhysicalInterface *eth;
int hash_id;
void RouterIdDepInit(Agent *agent) {
}
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.10", "00:00:01:01:01:01", 1, 1},
};
IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.1", true},
};
class BgpServiceTest : public ::testing::Test {
public:
void AddAap(std::string intf_name, int intf_id, Ip4Address ip,
const std::string &mac) {
std::ostringstream buf;
buf << "<virtual-machine-interface-allowed-address-pairs>";
buf << "<allowed-address-pair>";
buf << "<ip>";
buf << "<ip-prefix>" << ip.to_string() <<"</ip-prefix>";
buf << "<ip-prefix-len>"<< 32 << "</ip-prefix-len>";
buf << "</ip>";
buf << "<mac>" << mac << "</mac>";
buf << "<flag>" << "act-stby" << "</flag>";
buf << "</allowed-address-pair>";
buf << "</virtual-machine-interface-allowed-address-pairs>";
char cbuf[10000];
strcpy(cbuf, buf.str().c_str());
AddNode("virtual-machine-interface", intf_name.c_str(),
intf_id, cbuf);
client->WaitForIdle();
}
virtual void SetUp() {
agent_ = Agent::GetInstance();
flow_proto_ = agent_->pkt()->get_flow_proto();
client->WaitForIdle();
EXPECT_EQ(0U, flow_proto_->FlowCount());
CreateVmportEnv(input, 1);
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1",
"vrf1", "bgpaas-client",
false);
client->WaitForIdle();
}
virtual void TearDown() {
client->EnqueueFlowFlush();
client->WaitForIdle();
EXPECT_EQ(0U, flow_proto_->FlowCount());
client->WaitForIdle();
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1",
"vrf1", "bgpaas-server",
true);
DelIPAM("vn1");
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
}
Agent *agent_;
FlowProto *flow_proto_;
BgpPeer *peer;
};
TEST_F(BgpServiceTest, Test_1) {
peer = CreateBgpPeer("127.0.0.1", "remote");
client->WaitForIdle();
TxTcpPacket(VmInterfaceGet(1)->id(), "1.1.1.10", "1.1.1.1", 10000, 179,
false);
client->WaitForIdle();
FlowEntry *fe = FlowGet(VmInterfaceGet(1)->flow_key_nh()->id(),
"1.1.1.10", "1.1.1.1", 6, 10000, 179);
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
DeleteBgpPeer(peer);
client->WaitForIdle();
}
TEST_F(BgpServiceTest, Test_2) {
peer = CreateBgpPeer("127.0.0.1", "remote");
client->WaitForIdle();
TxTcpPacket(VmInterfaceGet(1)->id(), "1.1.1.10", "1.1.1.1", 10000, 179,
false);
client->WaitForIdle();
FlowEntry *fe = FlowGet(VmInterfaceGet(1)->flow_key_nh()->id(),
"1.1.1.10", "1.1.1.1", 6, 10000, 179);
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
//Explicitly call deleteall on bgp service tree.
//agent_->pkt()->flow_mgmt_manager()->ControllerNotify(0);
//agent_->pkt()->flow_mgmt_manager()->ControllerNotify(1);
client->WaitForIdle();
DeleteBgpPeer(peer);
client->WaitForIdle();
}
TEST_F(BgpServiceTest, Test_3) {
AddAap("vnet1", 1, Ip4Address::from_string("10.10.10.10"), "00:00:01:01:01:01");
peer = CreateBgpPeer("127.0.0.1", "remote");
client->WaitForIdle();
TxTcpPacket(VmInterfaceGet(1)->id(), "10.10.10.10", "1.1.1.1", 10000, 179,
false);
client->WaitForIdle();
FlowEntry *fe = FlowGet(VmInterfaceGet(1)->flow_key_nh()->id(),
"10.10.10.10", "1.1.1.1", 6, 10000, 179);
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
DeleteBgpPeer(peer);
client->WaitForIdle();
}
int main(int argc, char *argv[]) {
int ret = 0;
GETUSERARGS();
client = TestInit(init_file, ksync_init, true, true, true, 100*1000);
ret = RUN_ALL_TESTS();
usleep(100000);
TestShutdown();
delete client;
return ret;
}