Tests: Refactor duplicated code.
Naveen suggested earlier today that we should refactor duplicate code. This commit kicks off the effort. Change-Id: I855b0f40d41d1f3a2e673f3b254b76b596409656 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
This commit is contained in:

committed by
Neale Ranns

parent
9e52ef6024
commit
e8fece85e2
@ -1,3 +1,5 @@
|
||||
from socket import AF_INET6
|
||||
|
||||
from scapy.layers.dhcp6 import DHCP6_Advertise, DHCP6OptClientId, \
|
||||
DHCP6OptStatusCode, DHCP6OptPref, DHCP6OptIA_PD, DHCP6OptIAPrefix, \
|
||||
DHCP6OptServerId, DHCP6_Solicit, DHCP6_Reply, DHCP6_Request, DHCP6_Renew, \
|
||||
@ -6,20 +8,15 @@ from scapy.layers.dhcp6 import DHCP6_Advertise, DHCP6OptClientId, \
|
||||
from scapy.layers.inet6 import IPv6, Ether, UDP
|
||||
from scapy.utils6 import in6_mactoifaceid
|
||||
from scapy.utils import inet_ntop, inet_pton
|
||||
from socket import AF_INET6
|
||||
|
||||
from framework import VppTestCase
|
||||
import util
|
||||
|
||||
|
||||
def ip6_normalize(ip6):
|
||||
return inet_ntop(AF_INET6, inet_pton(AF_INET6, ip6))
|
||||
|
||||
|
||||
def mk_ll_addr(mac):
|
||||
euid = in6_mactoifaceid(mac)
|
||||
addr = "fe80::" + euid
|
||||
return addr
|
||||
|
||||
|
||||
class TestDHCPv6DataPlane(VppTestCase):
|
||||
""" DHCPv6 Data Plane Test Case """
|
||||
|
||||
@ -88,7 +85,7 @@ class TestDHCPv6DataPlane(VppTestCase):
|
||||
ia_na_opts = DHCP6OptIAAddress(addr='7:8::2', preflft=60,
|
||||
validlft=120)
|
||||
p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
|
||||
IPv6(src=mk_ll_addr(self.pg0.remote_mac),
|
||||
IPv6(src=util.mk_ll_addr(self.pg0.remote_mac),
|
||||
dst=self.pg0.local_ip6_ll) /
|
||||
UDP(sport=547, dport=546) /
|
||||
DHCP6_Advertise(trid=trid) /
|
||||
@ -165,7 +162,7 @@ class TestDHCPv6DataPlane(VppTestCase):
|
||||
ia_pd_opts = DHCP6OptIAPrefix(prefix='7:8::', plen=56, preflft=60,
|
||||
validlft=120)
|
||||
p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
|
||||
IPv6(src=mk_ll_addr(self.pg0.remote_mac),
|
||||
IPv6(src=util.mk_ll_addr(self.pg0.remote_mac),
|
||||
dst=self.pg0.local_ip6_ll) /
|
||||
UDP(sport=547, dport=546) /
|
||||
DHCP6_Advertise(trid=trid) /
|
||||
@ -317,7 +314,7 @@ class TestDHCPv6IANAControlPlane(VppTestCase):
|
||||
else:
|
||||
opt_ia_na = DHCP6OptIA_NA(iaid=1, T1=t1, T2=t2, ianaopts=ianaopts)
|
||||
p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
|
||||
IPv6(src=mk_ll_addr(self.pg0.remote_mac),
|
||||
IPv6(src=util.mk_ll_addr(self.pg0.remote_mac),
|
||||
dst=self.pg0.local_ip6_ll) /
|
||||
UDP(sport=547, dport=546) /
|
||||
msg_type(trid=self.trid) /
|
||||
@ -569,7 +566,7 @@ class TestDHCPv6PDControlPlane(VppTestCase):
|
||||
else:
|
||||
opt_ia_pd = DHCP6OptIA_PD(iaid=1, T1=t1, T2=t2, iapdopt=iapdopt)
|
||||
p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
|
||||
IPv6(src=mk_ll_addr(self.pg0.remote_mac),
|
||||
IPv6(src=util.mk_ll_addr(self.pg0.remote_mac),
|
||||
dst=self.pg0.local_ip6_ll) /
|
||||
UDP(sport=547, dport=546) /
|
||||
msg_type(trid=self.trid) /
|
||||
|
@ -18,7 +18,7 @@ from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
|
||||
from six import moves
|
||||
|
||||
from framework import VppTestCase, VppTestRunner
|
||||
from util import ppp, ip6_normalize
|
||||
from util import ppp, ip6_normalize, mk_ll_addr
|
||||
from vpp_ip import DpoProto
|
||||
from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
|
||||
VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
|
||||
@ -36,12 +36,6 @@ except NameError:
|
||||
text_type = str
|
||||
|
||||
|
||||
def mk_ll_addr(mac):
|
||||
euid = in6_mactoifaceid(mac)
|
||||
addr = "fe80::" + euid
|
||||
return addr
|
||||
|
||||
|
||||
class TestIPv6ND(VppTestCase):
|
||||
def validate_ra(self, intf, rx, dst_ip=None):
|
||||
if not dst_ip:
|
||||
|
@ -2,18 +2,19 @@
|
||||
|
||||
import abc
|
||||
import socket
|
||||
from socket import AF_INET6
|
||||
import six
|
||||
import sys
|
||||
import os.path
|
||||
from scapy.utils6 import in6_mactoifaceid
|
||||
|
||||
from scapy.layers.l2 import Ether
|
||||
from scapy.packet import Raw
|
||||
from scapy.layers.inet import IP
|
||||
from scapy.layers.inet6 import IPv6, IPv6ExtHdrFragment, IPv6ExtHdrRouting,\
|
||||
IPv6ExtHdrHopByHop
|
||||
from scapy.packet import Raw
|
||||
from scapy.utils import hexdump
|
||||
from socket import AF_INET6
|
||||
from scapy.utils6 import in6_mactoifaceid
|
||||
|
||||
from io import BytesIO
|
||||
from vpp_papi import mac_pton
|
||||
|
||||
@ -54,6 +55,7 @@ def ip4n_range(ip4n, s, e):
|
||||
for ip in ip4_range(ip4, s, e))
|
||||
|
||||
|
||||
# wrapper around scapy library function.
|
||||
def mk_ll_addr(mac):
|
||||
euid = in6_mactoifaceid(mac)
|
||||
addr = "fe80::" + euid
|
||||
|
Reference in New Issue
Block a user