#!/usr/bin/env python import binascii import socket from socket import AF_INET, AF_INET6 import unittest import sys from framework import VppTestCase from scapy.packet import Raw from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP, TCP from scapy.layers.inet6 import IPv6 from util import ppp class TestClassifier(VppTestCase): @staticmethod def _resolve_mask_match(mask_match): mask_match = binascii.unhexlify(mask_match) mask_match_len = ((len(mask_match) - 1) // 16 + 1) * 16 mask_match = mask_match + b'\0' * \ (mask_match_len - len(mask_match)) return mask_match, mask_match_len @classmethod def setUpClass(cls): """ Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP. """ super(TestClassifier, cls).setUpClass() cls.acl_active_table = '' cls.af = AF_INET def setUp(self): """ Perform test setup before test case. **Config:** - create 4 pg interfaces - untagged pg0/pg1/pg2 interface pg0 -------> pg1 (IP ACL) \ ---> pg2 (MAC ACL)) \ -> pg3 (PBR) - setup interfaces: - put it into UP state - set IPv4/6 addresses - resolve neighbor address using ARP :ivar list interfaces: pg interfaces. :ivar list pg_if_packet_sizes: packet sizes in test. :ivar dict acl_tbl_idx: ACL table index. :ivar int pbr_vrfid: VRF id for PBR test. """ self.reset_packet_infos() super(TestClassifier, self).setUp() if self.af is None: # l2_acl test case return # create 4 pg interfaces self.create_pg_interfaces(range(4)) # packet sizes to test self.pg_if_packet_sizes = [64, 9018] self.interfaces = list(self.pg_interfaces) # ACL & PBR vars self.acl_tbl_idx = {} self.pbr_vrfid = 200 # setup all interfaces for intf in self.interfaces: intf.admin_up() if self.af == AF_INET: intf.config_ip4() intf.resolve_arp() elif self.af == AF_INET6: intf.config_ip6() intf.resolve_ndp() def tearDown(self): """Run standard test teardown and acl related log.""" if self.af is not None and not self.vpp_dead: if self.af == AF_INET: self.logger.info(self.vapi.ppcli("show inacl type ip4")) self.logger.info(self.vapi.ppcli("show outacl type ip4")) elif self.af == AF_INET6: self.logger.info(self.vapi.ppcli("show inacl type ip6")) self.logger.info(self.vapi.ppcli("show outacl type ip6")) self.logger.info(self.vapi.cli("show classify table verbose")) self.logger.info(self.vapi.cli("show ip fib")) acl_active_table = 'ip_out' if self.af == AF_INET6: acl_active_table = 'ip6_out' if self.acl_active_table == acl_active_table: self.output_acl_set_interface( self.pg0, self.acl_tbl_idx.get(self.acl_active_table), 0) self.acl_active_table = '' elif self.acl_active_table != '': self.input_acl_set_interface( self.pg0, self.acl_tbl_idx.get(self.acl_active_table), 0) self.acl_active_table = '' for intf in self.interfaces: if self.af == AF_INET: intf.unconfig_ip4() elif self.af == AF_INET6: intf.unconfig_ip6() intf.admin_down() super(TestClassifier, self).tearDown() @staticmethod def build_mac_match(dst_mac='', src_mac='', ether_type=''): """Build MAC ACL match data with hexstring format. :param str dst_mac: source MAC address :param str src_mac: destination MAC address :param str ether_type: ethernet type <0-ffff> """ if dst_mac: dst_mac = dst_mac.replace(':', '') if src_mac: src_mac = src_mac.replace(':', '') return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format( dst_mac, src_mac, ether_type)).rstrip('0') @staticmethod def build_mac_mask(dst_mac='', src_mac='', ether_type=''): """Build MAC ACL mask data with hexstring format. :param str dst_mac: source MAC address <0-ffffffffffff> :param str src_mac: destination MAC address <0-ffffffffffff> :param str ether_type: ethernet type <0-ffff> """ return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format( dst_mac, src_mac, ether_type)).rstrip('0') @staticmethod def build_ip_mask(proto='', src_ip='', dst_ip='', src_port='', dst_port=''): """Build IP ACL mask data with hexstring format. :param str proto: protocol number <0-ff> :param str src_ip: source ip address <0-ffffffff> :param str dst_ip: destination ip address <0-ffffffff> :param str src_port: source port number <0-ffff> :param str dst_port: destination port number <0-ffff> """ return ('{!s:0>20}{!s:0>12}{!s:0>8}{!s:0>4}{!s:0>4}'.format( proto, src_ip, dst_ip, src_port, dst_port)).rstrip('0') @staticmethod def build_ip6_mask(nh='', src_ip='', dst_ip='', src_port='', dst_port=''): """Build IPv6 ACL mask data with hexstring format. :param str nh: next header number <0-ff> :param str src_ip: source ip address <0-ffffffff> :p
/*
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SRC_PLUGINS_STN_STN_MSG_ENUM_H_
#define SRC_PLUGINS_STN_STN_MSG_ENUM_H_

#include <vppinfra/byte_order.h>

#define vl_msg_id(n,h) n,
typedef enum
{
#include <stn/stn_all_api_h.h>
  /* We'll want to know how many messages IDs we need... */
  VL_MSG_FIRST_AVAILABLE,
} vl_msg_id_t;
#undef vl_msg_id

#endif /* SRC_PLUGINS_STN_STN_MSG_ENUM_H_ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")