aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEyal Bari <ebari@cisco.com>2017-01-11 13:39:54 +0200
committerJohn Lo <loj@cisco.com>2017-01-11 15:08:18 +0000
commitd81da8c0b5094de6635ad9575a2a2bb6f44070dc (patch)
treefc0c13e143b82a6c08e6d5253c38c1ceac4f4a5e /test
parent724f64ccf691e170973bdcdc6c09bfdc7e2ab5e4 (diff)
vxlan unit test - minor fixes
moved ip4_range and ip4n_range to util added n_ucast_tunnels Change-Id: I9140c4e54a0636d90a97db03da842f5183319af5 Signed-off-by: Eyal Bari <ebari@cisco.com>
Diffstat (limited to 'test')
-rw-r--r--test/template_bd.py15
-rw-r--r--test/test_vxlan.py39
-rw-r--r--test/util.py10
3 files changed, 35 insertions, 29 deletions
diff --git a/test/template_bd.py b/test/template_bd.py
index 6c384922bbd..91d5dd719f4 100644
--- a/test/template_bd.py
+++ b/test/template_bd.py
@@ -5,6 +5,8 @@ from abc import abstractmethod, ABCMeta
from scapy.layers.l2 import Ether, Raw
from scapy.layers.inet import IP, UDP
+from util import ip4_range
+
class BridgeDomain(object):
""" Bridge domain abstraction """
@@ -110,7 +112,7 @@ class BridgeDomain(object):
self.pg_start()
# Get packet from each tunnel and assert it's corectly encapsulated.
- out = self.pg0.get_capture(10)
+ out = self.pg0.get_capture(self.n_ucast_tunnels)
for pkt in out:
self.check_encapsulation(pkt, self.ucast_flood_bd, True)
payload = self.decapsulate(pkt)
@@ -135,10 +137,6 @@ class BridgeDomain(object):
payload = self.decapsulate(pkt)
self.assert_eq_pkts(payload, self.frame_reply)
- @staticmethod
- def ipn_to_ip(ipn):
- return '.'.join(str(i) for i in bytearray(ipn))
-
def test_mcast_rcv(self):
""" Multicast receive test
Send 20 encapsulated frames from pg0 only 10 match unicast tunnels
@@ -148,10 +146,9 @@ class BridgeDomain(object):
ip_range_start = 10
ip_range_end = 30
mcast_stream = [
- self.encap_mcast(self.frame_request, self.ipn_to_ip(ip), mac,
- self.mcast_flood_bd)
- for ip in self.ip4_range(self.pg0.remote_ip4n,
- ip_range_start, ip_range_end)]
+ self.encap_mcast(self.frame_request, ip, mac, self.mcast_flood_bd)
+ for ip in ip4_range(self.pg0.remote_ip4,
+ ip_range_start, ip_range_end)]
self.pg0.add_stream(mcast_stream)
self.pg2.enable_capture()
self.pg_start()
diff --git a/test/test_vxlan.py b/test/test_vxlan.py
index 845b8175b7b..9dccaf50fb1 100644
--- a/test/test_vxlan.py
+++ b/test/test_vxlan.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import socket
+from util import ip4n_range
import unittest
from framework import VppTestCase, VppTestRunner
from template_bd import BridgeDomain
@@ -34,7 +35,7 @@ class TestVxlan(BridgeDomain, VppTestCase):
Encapsulate the original payload frame by adding VXLAN header with its
UDP, IP and Ethernet fields
"""
- return (Ether(src=src_mac, dst=self.mcast_mac4) /
+ return (Ether(src=src_mac, dst=self.mcast_mac) /
IP(src=src_ip, dst=self.mcast_ip4) /
UDP(sport=self.dport, dport=self.dport, chksum=0) /
VXLAN(vni=vni, flags=self.flags) /
@@ -68,24 +69,19 @@ class TestVxlan(BridgeDomain, VppTestCase):
# Verify VNI
self.assertEqual(pkt[VXLAN].vni, vni)
- @staticmethod
- def ip4_range(ip4n, s=10, e=20):
- base = str(bytearray(ip4n)[:3])
- return ((base + ip) for ip in str(bytearray(range(s, e))))
-
@classmethod
- def create_vxlan_flood_test_bd(cls, vni):
+ def create_vxlan_flood_test_bd(cls, vni, n_ucast_tunnels):
# Create 10 ucast vxlan tunnels under bd
ip_range_start = 10
- ip_range_end = 20
+ ip_range_end = ip_range_start + n_ucast_tunnels
next_hop_address = cls.pg0.remote_ip4n
- for dest_addr in cls.ip4_range(next_hop_address, ip_range_start,
- ip_range_end):
- # add host route so dest_addr will not be resolved
- cls.vapi.ip_add_del_route(dest_addr, 32, next_hop_address)
+ for dest_ip4n in ip4n_range(next_hop_address, ip_range_start,
+ ip_range_end):
+ # add host route so dest_ip4n will not be resolved
+ cls.vapi.ip_add_del_route(dest_ip4n, 32, next_hop_address)
r = cls.vapi.vxlan_add_del_tunnel(
src_addr=cls.pg0.local_ip4n,
- dst_addr=dest_addr,
+ dst_addr=dest_ip4n,
vni=vni)
cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni)
@@ -93,12 +89,12 @@ class TestVxlan(BridgeDomain, VppTestCase):
def add_del_mcast_load(cls, is_add):
ip_range_start = 10
ip_range_end = 210
- for dest_addr in cls.ip4_range(cls.mcast_ip4n, ip_range_start,
- ip_range_end):
- vni = bytearray(dest_addr)[3]
+ for dest_ip4n in ip4n_range(cls.mcast_ip4n, ip_range_start,
+ ip_range_end):
+ vni = bytearray(dest_ip4n)[3]
cls.vapi.vxlan_add_del_tunnel(
src_addr=cls.pg0.local_ip4n,
- dst_addr=dest_addr,
+ dst_addr=dest_ip4n,
mcast_sw_if_index=1,
vni=vni,
is_add=is_add)
@@ -139,7 +135,7 @@ class TestVxlan(BridgeDomain, VppTestCase):
cls.mcast_ip4 = '239.1.1.1'
cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4)
iplong = atol(cls.mcast_ip4)
- cls.mcast_mac4 = "01:00:5e:%02x:%02x:%02x" % (
+ cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % (
(iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF)
# Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1
@@ -155,8 +151,10 @@ class TestVxlan(BridgeDomain, VppTestCase):
bd_id=cls.single_tunnel_bd)
# Setup vni 2 to test multicast flooding
+ cls.n_ucast_tunnels = 10
cls.mcast_flood_bd = 2
- cls.create_vxlan_flood_test_bd(cls.mcast_flood_bd)
+ cls.create_vxlan_flood_test_bd(cls.mcast_flood_bd,
+ cls.n_ucast_tunnels)
r = cls.vapi.vxlan_add_del_tunnel(
src_addr=cls.pg0.local_ip4n,
dst_addr=cls.mcast_ip4n,
@@ -173,7 +171,8 @@ class TestVxlan(BridgeDomain, VppTestCase):
# Setup vni 3 to test unicast flooding
cls.ucast_flood_bd = 3
- cls.create_vxlan_flood_test_bd(cls.ucast_flood_bd)
+ cls.create_vxlan_flood_test_bd(cls.ucast_flood_bd,
+ cls.n_ucast_tunnels)
cls.vapi.sw_interface_set_l2_bridge(cls.pg3.sw_if_index,
bd_id=cls.ucast_flood_bd)
except Exception:
diff --git a/test/util.py b/test/util.py
index 6658febfdb1..ae887a54543 100644
--- a/test/util.py
+++ b/test/util.py
@@ -34,6 +34,16 @@ def ppc(headline, capture, limit=10):
return "%s\n%s%s" % (headline, body, tail)
+def ip4_range(ip4, s, e):
+ tmp = ip4.rsplit('.', 1)[0]
+ return ("%s.%d" % (tmp, i) for i in range(s, e))
+
+
+def ip4n_range(ip4n, s, e):
+ ip4 = socket.inet_ntop(socket.AF_INET, ip4n)
+ return (socket.inet_pton(socket.AF_INET, ip) for ip in ip4_range(ip4, s, e))
+
+
class NumericConstant(object):
__metaclass__ = ABCMeta