from scapy.layers.inet import IP, UDP
from scapy.all import Raw
-from scapy.utils import rdpcap
-from resources.libraries.python.constants import Constants as con
from resources.libraries.python.SFC.SFCConstants import SFCConstants as sfccon
from resources.libraries.python.SFC.TunnelProtocol import VxLAN, VxLANGPE, NSH
-from robot.api import logger
def valid_ipv4(ipaddr):
"""Check if IP address has the correct IPv4 address format.
# get the NSH packet and check it
nsh_pkt = NSH(payload_data[8:32])
- if nsh_pkt.flags != sfccon.NSH_FLAGS:
- raise RuntimeError("Unexpected NSH flags: {0}".
- format(nsh_pkt.flags))
+ if nsh_pkt.Version != 0:
+ raise RuntimeError("Unexpected NSH version: {0}".
+ format(nsh_pkt.Version))
+
+ if nsh_pkt.OAM != 0 and nsh_pkt.OAM != 1:
+ raise RuntimeError("Unexpected NSH OAM: {0}".
+ format(nsh_pkt.OAM))
if nsh_pkt.length != sfccon.NSH_HEADER_LENGTH:
raise RuntimeError("NSH length {0} incorrect".
@staticmethod
- def check_the_nsh_sfc_packet(frame_size, test_type):
+ def check_the_nsh_sfc_packet(ether, frame_size, test_type):
"""
verify the NSH SFC functional test loopback packet field
is correct.
- :param frame_size: the origin frame size.
- :param test_type: the test type.
+ :param ether: The Ethernet packet data.
+ :param frame_size: The origin frame size.
+ :param test_type: The test type.
(Classifier, Proxy Inbound, Proxy Outbound, SFF).
+
+ :type ether: scapy.Ether
:type frame_size: Integer
:type test_type: str
:returns: none
:raises RuntimeError: If the packet field verify fails.
"""
- rx_pcapfile = '{0}/nsh_sfc_tests/sfc_scripts/temp_packet.pcap' \
- .format(con.REMOTE_FW_DIR)
-
- logger.trace('read pcap file:{0}'.format(rx_pcapfile))
-
- packets = rdpcap(rx_pcapfile)
- if len(packets) < 1:
- raise RuntimeError("No packet is received!")
-
- ether = packets[0]
-
origin_size = int(frame_size)
if test_type == "Classifier":
expect_pkt_len = origin_size + 74 - 4
recv_pkt_len = len(ether)
if recv_pkt_len != expect_pkt_len:
- raise RuntimeError("Received packet size {0} not " \
- "the expect size {1}".format(recv_pkt_len, \
- expect_pkt_len))
+ raise RuntimeError("Received packet size {0} not "
+ "the expect size {1}".format(recv_pkt_len,
+ expect_pkt_len))
if not ether.haslayer(IP):
raise RuntimeError("Not a IPv4 packet")