#!/usr/bin/env python from __future__ import print_function import binascii import random import socket import unittest import time import re from scapy.packet import Raw from scapy.layers.l2 import Ether from scapy.layers.inet import IP, TCP, UDP from scapy.layers.inet6 import IPv6 from framework import VppTestCase, VppTestRunner, running_extended_tests from vpp_object import VppObject from vpp_pg_interface import CaptureTimeoutError from util import ppp from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder from vpp_ip_route import VppIpRoute, VppRoutePath class VppCFLOW(VppObject): """CFLOW object for IPFIX exporter and Flowprobe feature""" def __init__(self, test, intf='pg2', active=0, passive=0, timeout=100, mtu=1024, datapath='l2', layer='l2 l3 l4'): self._test = test self._intf = intf self._active = active if passive == 0 or passive < active: self._passive = active+1 else: self._passive = passive self._datapath = datapath # l2 ip4 ip6 self._collect = layer # l2 l3 l4 self._timeout = timeout self._mtu = mtu self._configured = False def add_vpp_config(self): self.enable_exporter() self._test.vapi.flowprobe_params( record_l2=1 if 'l2' in self._collect.lower() else 0, record_l3=1 if 'l3' in self._collect.lower() else 0, record_l4=1 if 'l4' in self._collect.lower() else 0, active_timer=self._active, passive_timer=self._passive) self.enable_flowprobe_feature() self._test.vapi.cli("ipfix flush") self._configured = True def remove_vpp_config(self): self.disable_exporter() self.disable_flowprobe_feature() self._test.vapi.cli("ipfix flush") self._configured = False def enable_exporter(self): self._test.vapi.set_ipfix_exporter( collector_address=self._test.pg0.remote_ip4n, src_address=self._test.pg0.local_ip4n, path_mtu=self._mtu, template_interval=self._timeout) def enable_flowprobe_feature(self): self._test.vapi.ppcli("flowprobe feature add-del %s %s" % (self._intf, self._datapath)) def disable_exporter(self): self._test.vapi.cli("set ipfix exporter collector 0.0.0.0") def disable_flowprobe_feature(self): self._test.vapi.cli("flowprobe feature add-del %s %s disable" % (self._intf, self._datapath)) def object_id(self): return "ipfix-collector-%s-%s" % (self._src, self.dst) def query_vpp_config(self): return self._configured def verify_templates(self, decoder=None, timeout=1, count=3): templates = [] p = self._test.wait_for_cflow_packet(self._test.collector, 2, timeout) self._test.assertTrue(p.haslayer(IPFIX)) if decoder is not None and p.haslayer(Template): templates.append(p[Template].templateID) decoder.add_template(p.getlayer(Template)) if count > 1: p = self._test.wait_for_cflow_packet(self._test.collector, 2) self._test.assertTrue(p.haslayer(IPFIX)) if decoder is not None and p.haslayer(Template): templates.append(p[Template].templateID) decoder.add_template(p.getlayer(Template)) if count > 2: p = self._test.wait_for_cflow_packet(self._test.collector, 2) self._test.assertTrue(p.haslayer(IPFIX)) if decoder is not None and p.haslayer(Template): templates.append(p[Template].templateID) decoder.add_template(p.getlayer(Template)) return templates class MethodHolder(VppTestCase): """ Flow-per-packet plugin: test L2, IP4, IP6 reporting """ # Test variables debug_print = False max_number_of_packets = 10 pkts = [] @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(MethodHolder, cls).setUpClass() try: # Create pg interfaces cls.create_pg_interfaces(range(9)) # Packet sizes cls.pg_if_packet_sizes = [64, 512, 1518, 9018] # Create BD with MAC learning and unknown unicast flooding disabled # and put interfaces to this BD cls.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1, learn=1) cls.vapi.sw_interface_set_l2_bridge( rx_sw_if_index=cls.pg1._sw_if_index, bd_id=1) cls.vapi.sw_interface_set_l2_bridge( rx_sw_if_index=cls.pg2._sw_if_index, bd_id=1) # Set up all interfaces for i in cls.pg_interfaces: i.admin_up() cls.pg0.config_ip4() cls.pg0.configure_ipv4_neighbors() cls.collector = cls.pg0 cls.pg1.config_ip4() cls.pg1.resolve_arp() cls.pg2.config_ip4() cls.pg2.resolve_arp() cls.pg3.config_ip4() cls.pg3.resolve_arp() cls.pg4.config_ip4() cls.pg4.resolve_arp() cls.pg7.config_ip4() cls.pg8.config_ip4() cls.pg8.configure_ipv4_neighbors() cls.pg5.config_ip6() cls.pg5.resolve_ndp() cls.pg5.disable_ipv6_ra() cls.pg6.config_ip6() cls.pg6.resolve_ndp() cls.pg6.disable_ipv6_ra() except Exception: super(MethodHolder, cls).tearDownClass() raise @classmethod def tearDownClass(cls): super(MethodHolder, cls).tearDownClass() def create_stream(self, src_if=None, dst_if=None, packets=None, size=None, ip_ver='v4'): """Create a packet stream to tickle the plugin :param VppInterface src_if: Source interface for packet stream :param VppInterface src_if: Dst interface for packet stream """ if src_if is None: src_if = self.pg1 if dst_if is None: dst_if = self.pg2 self.pkts = [] if packets is
/*
* Copyright (c) 2017-2019 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 __included_tw_timer_16t_2w_512sl_h__
#define __included_tw_timer_16t_2w_512sl_h__
/* ... So that a client app can create multiple wheel geometries */
#undef TW_TIMER_WHEELS
#undef TW_SLOTS_PER_RING
#undef TW_RING_SHIFT
#undef TW_RING_MASK
#undef TW_TIMERS_PER_OBJECT
#undef LOG2_TW_TIMERS_PER_OBJECT
#undef TW_SUFFIX
#undef TW_OVERFLOW_VECTOR
#undef TW_FAST_WHEEL_BITMAP
#undef TW_TIMER_ALLOW_DUPLICATE_STOP
#undef TW_START_STOP_TRACE_SIZE
#define TW_TIMER_WHEELS 2
#define TW_SLOTS_PER_RING 512
#define TW_RING_SHIFT 9
#define TW_RING_MASK (TW_SLOTS_PER_RING -1)
#define TW_TIMERS_PER_OBJECT 16
#define LOG2_TW_TIMERS_PER_OBJECT 4
#define TW_SUFFIX _16t_2w_512sl
#define TW_FAST_WHEEL_BITMAP 0
#define TW_TIMER_ALLOW_DUPLICATE_STOP 1
#include <vppinfra/tw_timer_template.h>
#endif /* __included_tw_timer_16t_2w_512sl_h__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/