summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-05-09 16:09:52 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-05-12 09:47:42 +0900
commit9a4e8968ed731daec0b3f9289af85bbfbf39a336 (patch)
tree5f2563f6e5e3b874179987a5beaea78f8a04dde8
parent434b2adacda2895c3f2b7aea8b6ada4555f4a0bb (diff)
test_bgp: Add test cases for L2VPN Flow Spec
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/packet_data/bgp4/flowspec_nlri_l2vpn.pcapbin0 -> 241 bytes
-rw-r--r--ryu/tests/unit/packet/test_bgp.py81
2 files changed, 81 insertions, 0 deletions
diff --git a/ryu/tests/packet_data/bgp4/flowspec_nlri_l2vpn.pcap b/ryu/tests/packet_data/bgp4/flowspec_nlri_l2vpn.pcap
new file mode 100644
index 00000000..5236c831
--- /dev/null
+++ b/ryu/tests/packet_data/bgp4/flowspec_nlri_l2vpn.pcap
Binary files differ
diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py
index 62eb9d67..2211fc4c 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -109,6 +109,34 @@ RULES_BASE = [
bgp.FlowSpecDSCP(operator=bgp.FlowSpecDSCP.EQ, value=24),
]
+RULES_L2VPN_BASE = [
+ # ether_type=0x0800
+ bgp.FlowSpecEtherType(operator=bgp.FlowSpecEtherType.EQ, value=0x0800),
+ # source_mac='12:34:56:78:90:AB'
+ bgp.FlowSpecSourceMac(addr='12:34:56:78:90:AB', length=6),
+ # dest_mac='DE:EF:C0:FF:EE:DD'
+ bgp.FlowSpecDestinationMac(addr='BE:EF:C0:FF:EE:DD', length=6),
+ # llc_dsap=0x42
+ bgp.FlowSpecLLCDSAP(operator=bgp.FlowSpecLLCDSAP.EQ, value=0x42),
+ # llc_ssap=0x42
+ bgp.FlowSpecLLCSSAP(operator=bgp.FlowSpecLLCSSAP.EQ, value=0x42),
+ # llc_control=100
+ bgp.FlowSpecLLCControl(operator=bgp.FlowSpecLLCControl.EQ, value=100),
+ # snap=0x12345
+ bgp.FlowSpecSNAP(operator=bgp.FlowSpecSNAP.EQ, value=0x12345),
+ # vlan_id='>4000'
+ bgp.FlowSpecVLANID(operator=bgp.FlowSpecVLANID.GT, value=4000),
+ # vlan_cos='>=3'
+ bgp.FlowSpecVLANCoS(
+ operator=(bgp.FlowSpecVLANCoS.GT | bgp.FlowSpecVLANCoS.EQ), value=3),
+ # inner_vlan_id='<3000'
+ bgp.FlowSpecInnerVLANID(operator=bgp.FlowSpecInnerVLANID.LT, value=3000),
+ # inner_vlan_cos='<=5'
+ bgp.FlowSpecInnerVLANCoS(
+ operator=(bgp.FlowSpecInnerVLANCoS.LT | bgp.FlowSpecInnerVLANCoS.EQ),
+ value=5),
+]
+
class Test_bgp(unittest.TestCase):
""" Test case for ryu.lib.packet.bgp
@@ -352,6 +380,7 @@ class Test_bgp(unittest.TestCase):
'flowspec_nlri_vpn4',
'flowspec_nlri_ipv6',
'flowspec_nlri_vpn6',
+ 'flowspec_nlri_l2vpn',
'flowspec_action_traffic_rate',
'flowspec_action_traffic_action',
'flowspec_action_redirect',
@@ -372,6 +401,33 @@ class Test_bgp(unittest.TestCase):
eq_(buf, pkt.data,
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
+ def test_vlan_action_parser(self):
+ action = bgp.BGPFlowSpecVlanActionCommunity(
+ actions_1=(bgp.BGPFlowSpecVlanActionCommunity.POP |
+ bgp.BGPFlowSpecVlanActionCommunity.SWAP),
+ vlan_1=3000,
+ cos_1=3,
+ actions_2=bgp.BGPFlowSpecVlanActionCommunity.PUSH,
+ vlan_2=4000,
+ cos_2=2,
+ )
+ binmsg = action.serialize()
+ msg, rest = bgp.BGPFlowSpecVlanActionCommunity.parse(binmsg)
+ eq_(str(action), str(msg))
+ eq_(rest, b'')
+
+ def test_tpid_action_parser(self):
+ action = bgp.BGPFlowSpecTPIDActionCommunity(
+ actions=(bgp.BGPFlowSpecTPIDActionCommunity.TI |
+ bgp.BGPFlowSpecTPIDActionCommunity.TO),
+ tpid_1=5,
+ tpid_2=6,
+ )
+ binmsg = action.serialize()
+ msg, rest = bgp.BGPFlowSpecTPIDActionCommunity.parse(binmsg)
+ eq_(str(action), str(msg))
+ eq_(rest, b'')
+
def test_json1(self):
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
cap_value=b'hoge'),
@@ -730,3 +786,28 @@ class Test_bgp(unittest.TestCase):
msg3, rest = bgp.FlowSpecVPNv6NLRI.parser(binmsg)
eq_(str(msg), str(msg3))
eq_(rest, b'')
+
+ def test_flowspec_user_interface_l2vpn(self):
+ rules = RULES_L2VPN_BASE
+ msg = bgp.FlowSpecL2VPNNLRI.from_user(
+ route_dist='65001:250',
+ ether_type=0x0800,
+ src_mac='12:34:56:78:90:AB',
+ dst_mac='BE:EF:C0:FF:EE:DD',
+ llc_dsap=0x42,
+ llc_ssap=0x42,
+ llc_control=100,
+ snap=0x12345,
+ vlan_id='>4000',
+ vlan_cos='>=3',
+ inner_vlan_id='<3000',
+ inner_vlan_cos='<=5',
+ )
+ msg2 = bgp.FlowSpecL2VPNNLRI(route_dist='65001:250', rules=rules)
+ binmsg = msg.serialize()
+ binmsg2 = msg2.serialize()
+ eq_(str(msg), str(msg2))
+ eq_(binary_str(binmsg), binary_str(binmsg2))
+ msg3, rest = bgp.FlowSpecL2VPNNLRI.parser(binmsg)
+ eq_(str(msg), str(msg3))
+ eq_(rest, b'')