Skip to content

Commit

Permalink
add more unittest test case for l2vpn evpn
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Xiao <xiaoquwl@gmail.com>
  • Loading branch information
xiaopeng163 committed Jan 26, 2016
1 parent da22663 commit d542158
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 4 deletions.
8 changes: 4 additions & 4 deletions yabgp/message/attribute/nlri/evpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class EVPN(NLRI):
def parse(cls, nlri_data):
nlri_list = []
while nlri_data:
route_type = ord(nlri_data[0])
offset = ord(nlri_data[1])
route_type = ord(nlri_data[0:1])
offset = ord(nlri_data[1:2])
route_data = nlri_data[2: offset + 2]
route = {}
if route_type == bgp_cons.BGPNLRI_EVPN_ETHERNET_AUTO_DISCOVERY:
Expand Down Expand Up @@ -158,8 +158,8 @@ def parse(cls, data):
offset += 1
# ip address
if ip_addr_len != 0:
route['ip'] = str(netaddr.IPAddress(int(binascii.b2a_hex(data[offset: offset+ip_addr_len / 8]), 16)))
offset += ip_addr_len / 8
route['ip'] = str(netaddr.IPAddress(int(binascii.b2a_hex(data[offset: offset + int(ip_addr_len / 8)]), 16)))
offset += int(ip_addr_len / 8)
# label
route['label'] = MPLSVPN.parse_mpls_label_stack(data[offset:])
return route
Expand Down
51 changes: 51 additions & 0 deletions yabgp/tests/unit/message/attribute/test_mpreachnlri.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ def test_ipv4_flowspec_construct(self):
data_dict = {'afi_safi': (1, 133), 'nexthop': '', 'nlri': [{1: '192.85.2.0/24'}, {2: '192.85.1.0/24'}]}
self.assertEqual(data_bin, MpReachNLRI.construct(data_dict))

def test_l2vpn_evpn_parse_construct_route_type1(self):
data_dict = {
"afi_safi": (25, 70),
"nexthop": "10.75.44.254",
"nlri": [{
"type": 1,
"value": {
"rd": "1.1.1.1:32867",
"esi": 0,
"eth_tag_id": 100,
"label": [10]
}
}]
}
self.assertEqual(data_dict, MpReachNLRI.parse(MpReachNLRI.construct(data_dict)[3:]))

def test_l2vpn_evpn_parse_route_type2(self):
data_bin = b'\x80\x0e\x30\x00\x19\x46\x04\xac\x11\x00\x03\x00\x02\x25\x00\x01\xac\x11' \
b'\x00\x03\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6c' \
Expand Down Expand Up @@ -136,5 +152,40 @@ def test_l2vpn_evpn_construct_route_type2(self):

self.assertEqual(data_bin, MpReachNLRI.construct(data_dict))

def test_l2vpn_evpn_parse_construct_route_type3(self):
data_dict = {
"afi_safi": (25, 70),
"nexthop": "10.75.44.254",
"nlri": [
{
"type": 3,
"value": {
"rd": "172.16.0.1:5904",
"eth_tag_id": 100,
"ip": "192.168.0.1"
}
}
]
}
self.assertEqual(data_dict, MpReachNLRI.parse(MpReachNLRI.construct(data_dict)[3:]))

def test_l2vpn_evpn_parse_construct_route_type4(self):
data_dict = {
"afi_safi": (25, 70),
"nexthop": "10.75.44.254",
"nlri": [
{
"type": 4,
"value": {
"rd": "172.16.0.1:8888",
"esi": 0,
"ip": "192.168.0.1"
}
}
]
}
self.assertEqual(data_dict, MpReachNLRI.parse(MpReachNLRI.construct(data_dict)[3:]))


if __name__ == '__main__':
unittest.main()
46 changes: 46 additions & 0 deletions yabgp/tests/unit/message/attribute/test_mpunreachnlri.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ def test_ipv4_flowspec_construct(self):
nlri_dict = {'afi_safi': (1, 133), 'withdraw': [{1: '192.85.2.0/24'}, {2: '192.85.1.0/24'}]}
self.assertEqual(data_bin, MpUnReachNLRI.construct(nlri_dict)[3:])

def test_l2vpn_evpn_route_type_1_parse_construct(self):
data_dict = {
"afi_safi": (25, 70),
"withdraw": [{
"type": 1,
"value": {
"rd": "1.1.1.1:32867",
"esi": 0,
"eth_tag_id": 100,
"label": [10]
}
}]}
self.assertEqual(data_dict, MpUnReachNLRI.parse(MpUnReachNLRI.construct(data_dict)[3:]))

def test_l2vpn_evpn_route_type_2_parse_construct(self):
data_dict = {
'afi_safi': (25, 70),
Expand All @@ -76,6 +90,38 @@ def test_l2vpn_evpn_route_type_2_parse_construct(self):
}
self.assertEqual(data_dict, MpUnReachNLRI.parse(MpUnReachNLRI.construct(data_dict)[3:]))

def test_l2vpn_evpn_route_type_3_parse_construct(self):
data_dict = {
"afi_safi": (25, 70),
"withdraw": [
{
"type": 3,
"value": {
"rd": "172.16.0.1:5904",
"eth_tag_id": 100,
"ip": "192.168.0.1"
}
}
]
}
self.assertEqual(data_dict, MpUnReachNLRI.parse(MpUnReachNLRI.construct(data_dict)[3:]))

def test_l2vpn_evpn_route_type_4_parse_construct(self):
data_dict = {
"afi_safi": (25, 70),
"withdraw": [
{
"type": 4,
"value": {
"rd": "172.16.0.1:8888",
"esi": 0,
"ip": "192.168.0.1"
}
}
]
}
self.assertEqual(data_dict, MpUnReachNLRI.parse(MpUnReachNLRI.construct(data_dict)[3:]))


if __name__ == '__main__':
unittest.main()
30 changes: 30 additions & 0 deletions yabgp/tests/unit/message/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,35 @@ def test_parse_ipv4_mpls_vpn_withdraw(self):
'prefix': '192.168.201.0/24'}]}}}
self.assertEqual(data_hoped['attr'], Update.parse(None, data_bin[HDR_LEN:], True)['attr'])

def test_parse_construct_l2vpn_evpn(self):
data_bin = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x63\x02\x00\x00\x00' \
b'\x4c\xc0\x10\x08\x06\x00\x01\x00\x00\x00\x01\xf4\x40\x01\x01\x00\x40\x02\x00\x40\x05\x04' \
b'\x00\x00\x00\x64\x80\x0e\x30\x00\x19\x46\x04\x0a\x4b\x2c\xfe\x00\x02\x25\x00\x01\xac\x11' \
b'\x00\x03\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6c\x30\x00\x11\x22' \
b'\x33\x44\x55\x20\x0b\x0b\x0b\x01\x00\x00\x00'
data_dict = {
"attr": {
1: 0,
2: [],
5: 100,
14: {
"afi_safi": (25, 70),
"nexthop": "10.75.44.254",
"nlri": [
{
"type": 2,
"value": {
"eth_tag_id": 108,
"ip": "11.11.11.1",
"label": [0],
"rd": "172.17.0.3:2",
"mac": "00-11-22-33-44-55",
"esi": 0}}]
},
16: [[1536, 1, 500]]
}}
self.assertEqual(data_bin, Update.construct(msg_dict=data_dict))
self.assertEqual(data_dict['attr'], Update.parse(None, data_bin[HDR_LEN:])['attr'])

if __name__ == '__main__':
unittest.main()

0 comments on commit d542158

Please sign in to comment.