Signed-off-by: Satoshi Fujimoto <[email protected]>
---
 ryu/tests/packet_data/bgp4/flowspec_nlri_ipv6.pcap | Bin 0 -> 264 bytes
 ryu/tests/packet_data/bgp4/flowspec_nlri_vpn6.pcap | Bin 0 -> 273 bytes
 ryu/tests/unit/packet/test_bgp.py                  | 278 ++++++++++++++++-----
 3 files changed, 213 insertions(+), 65 deletions(-)
 create mode 100644 ryu/tests/packet_data/bgp4/flowspec_nlri_ipv6.pcap
 create mode 100644 ryu/tests/packet_data/bgp4/flowspec_nlri_vpn6.pcap

diff --git a/ryu/tests/packet_data/bgp4/flowspec_nlri_ipv6.pcap 
b/ryu/tests/packet_data/bgp4/flowspec_nlri_ipv6.pcap
new file mode 100644
index 
0000000000000000000000000000000000000000..82534a61c97ef2524e17bf322349e8d52336fb6f
GIT binary patch
literal 264
zcmca|c+)~A1{MYcU}0bca&+{bM;zP3%kTim24OH@0+Wm!46Y0emkzykU|?ihWX8q7
zzzD=lr|TIuo3W-mp6su(yFr4%O5`|Df{}xZAx85JLyY9U|7d_=9>}<M2S!FF2PQTq
zprwCbHt>ZoFtsu;_%SvpD1e-S08C5`3<eMfzyz6@8`)SI16Zf9UtpWWy@S1xjiZr)
z(^;rlfomf33vNcSMhTt<Cf>%B0|E*S91K85GH^ApF)%otU|?wA1e=o5zz(LF0gpgB
A-T(jq

literal 0
HcmV?d00001

diff --git a/ryu/tests/packet_data/bgp4/flowspec_nlri_vpn6.pcap 
b/ryu/tests/packet_data/bgp4/flowspec_nlri_vpn6.pcap
new file mode 100644
index 
0000000000000000000000000000000000000000..cdf4c1c08e6a8cad29c5b4477752556f07a4431e
GIT binary patch
literal 273
zcmca|c+)~A1{MYcU}0bca@rogifCeBW_Sr?gD@B{fk{RV23H1#+wZI$7#!Hl?{hIQ
zFaj|X!{)_PS>7+QTG1K%zd?e*Qse?qf{}xZK_)hXLB{{de>A|b9Aw-C2S!FF2POsw
zR*)M~8u(%unA#W^!WbC-f~;j^Y*0`Dxd#E5m>L)iATEIkGBY=_u`~v-PGP^mHi>%&
zdm|f1BLk<iP_qKpMCKRVjAD%vJPk~|jVT8N6o3u|x|V^ffsKK|=>!8q11H#&lm>P%
G%?tqE9Xrzi

literal 0
HcmV?d00001

diff --git a/ryu/tests/unit/packet/test_bgp.py 
b/ryu/tests/unit/packet/test_bgp.py
index a3b7a68..62eb9d6 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -44,6 +44,71 @@ PMSI_TYPE_INGRESS_REPLICATION = (
     bgp.BGPPathAttributePmsiTunnel.TYPE_INGRESS_REPLICATION
 )
 
+RULES_BASE = [
+    # port='>=8000'
+    bgp.FlowSpecPort(
+        operator=(bgp.FlowSpecPort.GT | bgp.FlowSpecPort.EQ),
+        value=8000),
+    # port='&<=9000'
+    bgp.FlowSpecPort(
+        operator=(bgp.FlowSpecPort.AND | bgp.FlowSpecPort.LT |
+                  bgp.FlowSpecPort.EQ),
+        value=9000),
+    # port='==80'
+    bgp.FlowSpecPort(operator=bgp.FlowSpecPort.EQ, value=80),
+    # dst_port=8080
+    bgp.FlowSpecDestPort(operator=bgp.FlowSpecDestPort.EQ, value=8080),
+    # dst_port='>9000'
+    bgp.FlowSpecDestPort(operator=bgp.FlowSpecDestPort.GT, value=9000),
+    # dst_port='&<9050'
+    bgp.FlowSpecDestPort(
+        operator=(bgp.FlowSpecDestPort.AND | bgp.FlowSpecDestPort.LT),
+        value=9050),
+    # dst_port='<=1000'
+    bgp.FlowSpecDestPort(
+        operator=(bgp.FlowSpecDestPort.LT | bgp.FlowSpecDestPort.EQ),
+        value=1000),
+    # src_port='<=9090'
+    bgp.FlowSpecSrcPort(
+        operator=(bgp.FlowSpecSrcPort.LT | bgp.FlowSpecSrcPort.EQ),
+        value=9090),
+    # src_port='& >=9080'
+    bgp.FlowSpecSrcPort(
+        operator=(bgp.FlowSpecSrcPort.AND | bgp.FlowSpecSrcPort.GT |
+                  bgp.FlowSpecSrcPort.EQ),
+        value=9080),
+    # src_port='<10100'
+    bgp.FlowSpecSrcPort(
+        operator=bgp.FlowSpecSrcPort.LT, value=10100),
+    # src_port='>10000'
+    bgp.FlowSpecSrcPort(
+        operator=(bgp.FlowSpecSrcPort.AND | bgp.FlowSpecSrcPort.GT),
+        value=10000),
+    # icmp_type=0
+    bgp.FlowSpecIcmpType(operator=bgp.FlowSpecIcmpType.EQ, value=0),
+    # icmp_code=6
+    bgp.FlowSpecIcmpCode(operator=bgp.FlowSpecIcmpCode.EQ, value=6),
+    # tcp_flags='ACK+FIN'
+    bgp.FlowSpecTCPFlags(
+        operator=0,  # Partial match
+        value=(bgp.FlowSpecTCPFlags.SYN | bgp.FlowSpecTCPFlags.ACK)),
+    # tcp_flags='&!=URGENT'
+    bgp.FlowSpecTCPFlags(
+        operator=(bgp.FlowSpecTCPFlags.AND | bgp.FlowSpecTCPFlags.NOT),
+        value=bgp.FlowSpecTCPFlags.URGENT),
+    # packet_len=1000
+    bgp.FlowSpecPacketLen(
+        operator=bgp.FlowSpecPacketLen.EQ, value=1000),
+    # packet_len=1100
+    bgp.FlowSpecPacketLen(
+        operator=(bgp.FlowSpecTCPFlags.AND | bgp.FlowSpecPacketLen.EQ),
+        value=1100),
+    # dscp=22
+    bgp.FlowSpecDSCP(operator=bgp.FlowSpecDSCP.EQ, value=22),
+    # dscp=24
+    bgp.FlowSpecDSCP(operator=bgp.FlowSpecDSCP.EQ, value=24),
+]
+
 
 class Test_bgp(unittest.TestCase):
     """ Test case for ryu.lib.packet.bgp
@@ -285,6 +350,8 @@ class Test_bgp(unittest.TestCase):
             'evpn_nlri_ip_prefix',
             'flowspec_nlri_ipv4',
             'flowspec_nlri_vpn4',
+            'flowspec_nlri_ipv6',
+            'flowspec_nlri_vpn6',
             'flowspec_action_traffic_rate',
             'flowspec_action_traffic_action',
             'flowspec_action_redirect',
@@ -449,8 +516,8 @@ class Test_bgp(unittest.TestCase):
         msg2 = bgp.BGPUpdate.from_jsondict(jsondict['BGPUpdate'])
         eq_(str(msg1), str(msg2))
 
-    def test_user_interface(self):
-        rules = [
+    def test_flowspec_user_interface_ipv4(self):
+        rules = RULES_BASE + [
             # dst_prefix='10.0.0.0/24
             bgp.FlowSpecDestPrefix(addr='10.0.0.0', length=24),
             # src_prefix='20.0.0.1/24'
@@ -458,68 +525,6 @@ class Test_bgp(unittest.TestCase):
             # ip_proto='6'
             bgp.FlowSpecIPProtocol(
                 operator=bgp.FlowSpecIPProtocol.EQ, value=6),
-            # port='>=8000'
-            bgp.FlowSpecPort(
-                operator=(bgp.FlowSpecPort.GT | bgp.FlowSpecPort.EQ),
-                value=8000),
-            # port='&<=9000'
-            bgp.FlowSpecPort(
-                operator=(bgp.FlowSpecPort.AND | bgp.FlowSpecPort.LT |
-                          bgp.FlowSpecPort.EQ),
-                value=9000),
-            # port='==80'
-            bgp.FlowSpecPort(operator=bgp.FlowSpecPort.EQ, value=80),
-            # dst_port=8080
-            bgp.FlowSpecDestPort(operator=bgp.FlowSpecDestPort.EQ, value=8080),
-            # dst_port='>9000'
-            bgp.FlowSpecDestPort(operator=bgp.FlowSpecDestPort.GT, value=9000),
-            # dst_port='&<9050'
-            bgp.FlowSpecDestPort(
-                operator=(bgp.FlowSpecDestPort.AND | bgp.FlowSpecDestPort.LT),
-                value=9050),
-            # dst_port='<=1000'
-            bgp.FlowSpecDestPort(
-                operator=(bgp.FlowSpecDestPort.LT | bgp.FlowSpecDestPort.EQ),
-                value=1000),
-            # src_port='<=9090'
-            bgp.FlowSpecSrcPort(
-                operator=(bgp.FlowSpecSrcPort.LT | bgp.FlowSpecSrcPort.EQ),
-                value=9090),
-            # src_port='& >=9080'
-            bgp.FlowSpecSrcPort(
-                operator=(bgp.FlowSpecSrcPort.AND | bgp.FlowSpecSrcPort.GT |
-                          bgp.FlowSpecSrcPort.EQ),
-                value=9080),
-            # src_port='<10100'
-            bgp.FlowSpecSrcPort(
-                operator=bgp.FlowSpecSrcPort.LT, value=10100),
-            # src_port='>10000'
-            bgp.FlowSpecSrcPort(
-                operator=(bgp.FlowSpecSrcPort.AND | bgp.FlowSpecSrcPort.GT),
-                value=10000),
-            # icmp_type=0
-            bgp.FlowSpecIcmpType(operator=bgp.FlowSpecIcmpType.EQ, value=0),
-            # icmp_code=6
-            bgp.FlowSpecIcmpCode(operator=bgp.FlowSpecIcmpCode.EQ, value=6),
-            # tcp_flags='ACK+FIN'
-            bgp.FlowSpecTCPFlags(
-                operator=0,  # Partial match
-                value=(bgp.FlowSpecTCPFlags.SYN | bgp.FlowSpecTCPFlags.ACK)),
-            # tcp_flags='&!=URGENT'
-            bgp.FlowSpecTCPFlags(
-                operator=(bgp.FlowSpecTCPFlags.AND | bgp.FlowSpecTCPFlags.NOT),
-                value=bgp.FlowSpecTCPFlags.URGENT),
-            # packet_len=1000
-            bgp.FlowSpecPacketLen(
-                operator=bgp.FlowSpecPacketLen.EQ, value=1000),
-            # packet_len=1100
-            bgp.FlowSpecPacketLen(
-                operator=(bgp.FlowSpecTCPFlags.AND | bgp.FlowSpecPacketLen.EQ),
-                value=1100),
-            # dscp=22
-            bgp.FlowSpecDSCP(operator=bgp.FlowSpecDSCP.EQ, value=22),
-            # dscp=24
-            bgp.FlowSpecDSCP(operator=bgp.FlowSpecDSCP.EQ, value=24),
             # fragment='LF'
             bgp.FlowSpecFragment(
                 operator=0,  # Partial match
@@ -536,7 +541,8 @@ class Test_bgp(unittest.TestCase):
             # fragment='!=DF'
             bgp.FlowSpecFragment(
                 operator=bgp.FlowSpecFragment.NOT,
-                value=bgp.FlowSpecFragment.DF)]
+                value=bgp.FlowSpecFragment.DF)
+        ]
 
         msg = bgp.FlowSpecIPv4NLRI.from_user(
             dst_prefix='10.0.0.0/24',
@@ -560,6 +566,33 @@ class Test_bgp(unittest.TestCase):
         eq_(str(msg), str(msg3))
         eq_(rest, b'')
 
+    def test_flowspec_user_interface_vpv4(self):
+        rules = RULES_BASE + [
+            # dst_prefix='10.0.0.0/24
+            bgp.FlowSpecDestPrefix(addr='10.0.0.0', length=24),
+            # src_prefix='20.0.0.1/24'
+            bgp.FlowSpecSrcPrefix(addr='20.0.0.0', length=24),
+            # ip_proto='6'
+            bgp.FlowSpecIPProtocol(
+                operator=bgp.FlowSpecIPProtocol.EQ, value=6),
+            # fragment='LF'
+            bgp.FlowSpecFragment(
+                operator=0,  # Partial match
+                value=bgp.FlowSpecFragment.LF),
+            # fragment='==FF'
+            bgp.FlowSpecFragment(
+                operator=bgp.FlowSpecFragment.MATCH,
+                value=bgp.FlowSpecFragment.FF),
+            # fragment='&==ISF'
+            bgp.FlowSpecFragment(
+                operator=(bgp.FlowSpecFragment.AND |
+                          bgp.FlowSpecFragment.MATCH),
+                value=bgp.FlowSpecFragment.ISF),
+            # fragment='!=DF'
+            bgp.FlowSpecFragment(
+                operator=bgp.FlowSpecFragment.NOT,
+                value=bgp.FlowSpecFragment.DF)
+        ]
         msg = bgp.FlowSpecVPNv4NLRI.from_user(
             route_dist='65001:250',
             dst_prefix='10.0.0.0/24',
@@ -582,3 +615,118 @@ class Test_bgp(unittest.TestCase):
         msg3, rest = bgp.FlowSpecVPNv4NLRI.parser(binmsg)
         eq_(str(msg), str(msg3))
         eq_(rest, b'')
+
+    def test_flowspec_user_interface_ipv6(self):
+        rules = RULES_BASE + [
+            # dst_prefix='2001:2/128/32'
+            bgp.FlowSpecIPv6DestPrefix(
+                addr='2001::2', offset=32, length=128),
+            # src_prefix='3002::3/128'
+            bgp.FlowSpecIPv6SrcPrefix(
+                addr='3002::3', length=128),
+            # ip_proto='6'
+            bgp.FlowSpecNextHeader(
+                operator=bgp.FlowSpecNextHeader.EQ, value=6),
+            # fragment='LF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=0,  # Partial match
+                value=bgp.FlowSpecFragment.LF),
+            # fragment='==FF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=bgp.FlowSpecFragment.MATCH,
+                value=bgp.FlowSpecFragment.FF),
+            # fragment='&==ISF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=(bgp.FlowSpecFragment.AND |
+                          bgp.FlowSpecFragment.MATCH),
+                value=bgp.FlowSpecFragment.ISF),
+            # fragment='!=LF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=bgp.FlowSpecFragment.NOT,
+                value=bgp.FlowSpecFragment.LF),
+            # flowlabel='100'
+            bgp.FlowSpecIPv6FlowLabel(
+                operator=bgp.FlowSpecIPv6FlowLabel.EQ,
+                value=100),
+        ]
+        msg = bgp.FlowSpecIPv6NLRI.from_user(
+            dst_prefix='2001::2/128/32',
+            src_prefix='3002::3/128',
+            next_header='6',
+            port='>=8000 & <=9000 | ==80',
+            dst_port='8080 >9000&<9050 | <=1000',
+            src_port='<=9090 & >=9080 <10100 & >10000',
+            icmp_type=0,
+            icmp_code=6,
+            tcp_flags='SYN+ACK & !=URGENT',
+            packet_len='1000 & 1100',
+            dscp='22 24',
+            fragment='LF ==FF&==ISF | !=LF',
+            flow_label=100,
+        )
+        msg2 = bgp.FlowSpecIPv6NLRI(rules=rules)
+        binmsg = msg.serialize()
+        binmsg2 = msg2.serialize()
+        eq_(str(msg), str(msg2))
+        eq_(binary_str(binmsg), binary_str(binmsg2))
+        msg3, rest = bgp.FlowSpecIPv6NLRI.parser(binmsg)
+        eq_(str(msg), str(msg3))
+        eq_(rest, b'')
+
+    def test_flowspec_user_interface_vpnv6(self):
+        rules = RULES_BASE + [
+            # dst_prefix='2001:2/128/32'
+            bgp.FlowSpecIPv6DestPrefix(
+                addr='2001::2', offset=32, length=128),
+            # src_prefix='3002::3/128'
+            bgp.FlowSpecIPv6SrcPrefix(
+                addr='3002::3', length=128),
+            # ip_proto='6'
+            bgp.FlowSpecNextHeader(
+                operator=bgp.FlowSpecNextHeader.EQ, value=6),
+            # fragment='LF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=0,  # Partial match
+                value=bgp.FlowSpecFragment.LF),
+            # fragment='==FF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=bgp.FlowSpecFragment.MATCH,
+                value=bgp.FlowSpecFragment.FF),
+            # fragment='&==ISF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=(bgp.FlowSpecFragment.AND |
+                          bgp.FlowSpecFragment.MATCH),
+                value=bgp.FlowSpecFragment.ISF),
+            # fragment='!=LF'
+            bgp.FlowSpecIPv6Fragment(
+                operator=bgp.FlowSpecFragment.NOT,
+                value=bgp.FlowSpecFragment.LF),
+            # flowlabel='100'
+            bgp.FlowSpecIPv6FlowLabel(
+                operator=bgp.FlowSpecIPv6FlowLabel.EQ,
+                value=100),
+        ]
+        msg = bgp.FlowSpecVPNv6NLRI.from_user(
+            route_dist='65001:250',
+            dst_prefix='2001::2/128/32',
+            src_prefix='3002::3/128',
+            next_header='6',
+            port='>=8000 & <=9000 | ==80',
+            dst_port='8080 >9000&<9050 | <=1000',
+            src_port='<=9090 & >=9080 <10100 & >10000',
+            icmp_type=0,
+            icmp_code=6,
+            tcp_flags='SYN+ACK & !=URGENT',
+            packet_len='1000 & 1100',
+            dscp='22 24',
+            fragment='LF ==FF&==ISF | !=LF',
+            flow_label=100,
+        )
+        msg2 = bgp.FlowSpecVPNv6NLRI(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.FlowSpecVPNv6NLRI.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