Signed-off-by: Satoshi Fujimoto <[email protected]>
---
 .../packet_data/bgp4/flowspec_nlri_l2vpn.pcap      | Bin 0 -> 241 bytes
 ryu/tests/unit/packet/test_bgp.py                  |  81 +++++++++++++++++++++
 2 files changed, 81 insertions(+)
 create mode 100644 ryu/tests/packet_data/bgp4/flowspec_nlri_l2vpn.pcap

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 
0000000000000000000000000000000000000000..5236c83149fdb9d09e98c7cba118ca12c98d5149
GIT binary patch
literal 241
zcmca|c+)~A1{MYcU}0bca{jD)8}V``1H(xm8-&4t2~09_Ft{=>?B06Gfx&^TAcKp6
zff0zA7JOvbtn1{+{#-rcK!XH>mB<F51S1C*gX=$Y2G_45|Iq+LJIJ^K2S!FF2POsw
zR*)M~8u)A&B-<Dm%s?Cv=9|R9z|Xet{i%O)>jl_=B0xh0o1%nTQiPjMh)iMB5uL_<
pL9CHUyzzuYBl7_Pg$AG^mtPDF4IB(WS21ukaDp{yG_ZqdW&n!zJm&xa

literal 0
HcmV?d00001

diff --git a/ryu/tests/unit/packet/test_bgp.py 
b/ryu/tests/unit/packet/test_bgp.py
index 62eb9d6..2211fc4 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'')
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to