summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-05-09 16:09:44 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-05-12 09:46:31 +0900
commit64b9dfcdd67875e7c0e1e32c57fd3d6301269ad4 (patch)
treeb9bc01b6b2ec3f7c45b5c24c5181b6e76765588a
parent607f4d827674ab294a4155a65c987de559883296 (diff)
test_bgp: Add test cases for IPv6 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_ipv6.pcapbin0 -> 264 bytes
-rw-r--r--ryu/tests/packet_data/bgp4/flowspec_nlri_vpn6.pcapbin0 -> 273 bytes
-rw-r--r--ryu/tests/unit/packet/test_bgp.py278
3 files changed, 213 insertions, 65 deletions
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 00000000..82534a61
--- /dev/null
+++ b/ryu/tests/packet_data/bgp4/flowspec_nlri_ipv6.pcap
Binary files differ
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 00000000..cdf4c1c0
--- /dev/null
+++ b/ryu/tests/packet_data/bgp4/flowspec_nlri_vpn6.pcap
Binary files differ
diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py
index a3b7a68f..62eb9d67 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'')