#!/usr/bin/env python import unittest from framework import VppTestCase, VppTestRunner from vpp_object import VppObject from vpp_neighbor import VppNeighbor from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, DpoProto from scapy.packet import Raw from scapy.layers.l2 import Ether, ARP from scapy.layers.inet import IP, UDP from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6NDOptSrcLLAddr, \ ICMPv6ND_NA from scapy.utils6 import in6_getnsma, in6_getnsmac from socket import AF_INET, AF_INET6 from scapy.utils import inet_pton, inet_ntop from util import mactobinary class VppGbpEndpoint(VppObject): """ GBP Endpoint """ @property def bin_mac(self): return mactobinary(self.itf.remote_mac) @property def mac(self): return self.itf.remote_mac def __init__(self, test, itf, epg, recirc, ip, fip, is_ip6=False): self._test = test self.itf = itf self.epg = epg self.recirc = recirc self.ip = ip self.floating_ip = fip self.is_ip6 = is_ip6 if is_ip6: self.proto = DpoProto.DPO_PROTO_IP6 self.af = AF_INET6 self.is_ip6 = True self.ip_len = 128 else: self.proto = DpoProto.DPO_PROTO_IP4 self.af = AF_INET self.is_ip6 = False self.ip_len = 32 self.ip_n = inet_pton(self.af, ip) self.floating_ip_n = inet_pton(self.af, fip) def add_vpp_config(self): self._test.vapi.gbp_endpoint_add_del( 1, self.itf.sw_if_index, self.ip_n, self.is_ip6, self.epg.epg) self._test.registry.register(self, self._test.logger) def remove_vpp_config(self): self._test.vapi.gbp_endpoint_add_del( 0, self.itf.sw_if_index, self.ip_n, self.is_ip6, self.epg.epg) def __str__(self): return self.object_id() def object_id(self): return "gbp-endpoint;[%d:%s:%d]" % (self.itf.sw_if_index, self.ip, self.epg.epg) def query_vpp_config(self): eps = self._test.vapi.gbp_endpoint_dump() for ep in eps: if self.is_ip6: if ep.endpoint.address == self.ip_n \ and ep.endpoint.sw_if_index == self.itf.sw_if_index: return True else: if ep.endpoint.address[:4] == self.ip_n \ and ep.endpoint.sw_if_index == self.itf.sw_if_index: return True return False class VppGbpRecirc(VppObject): """ GBP Recirculation Interface """ def __init__(self, test, epg, recirc, is_ext=False): self._test = test self.recirc = recirc self.epg = epg self.is_ext = is_ext def add_vpp_config(self): self._test.vapi.gbp_recirc_add_del( 1, self.recirc.sw_if_index, self.epg.epg, self.is_ext) self._test.registry.register(self, self._test.logger) def remove_vpp_config(self): self._test.vapi.gbp_recirc_add_del( 0, self.recirc.sw_if_index, self.epg.epg, self.is_ext) def __str__(self): return self.object_id() def object_id(self): return "gbp-recirc;[%d]" % (self.recirc.sw_if_index) def query_vpp_config(self): rs = self._test.vapi.gbp_recirc_dump() for r in rs: if r.recirc.sw_if_index == self.recirc.sw_if_index: return True return False class VppGbpSubnet(VppObject): """ GBP Subnet """ def __init__(self, test, table_id, address, address_len, is_internal=True, is_ip6=False, sw_if_index=None, epg=None): self._test = test self.table_id = table_id self.address = address self.address_len = address_len self.is_ip6 = is_ip6 if is_ip6: self.address_n = inet_pton(AF_INET6, address) else: self.address_n = inet_pton(AF_INET, address) self.is_internal = is_internal self.sw_if_index = sw_if_index self.epg = epg def add_vpp_config(self): self._test.vapi.gbp_subnet_add_del( 1, self.table_id, self.is_internal, self.address_n, self.address_len, sw_if_index=self.sw_if_index if self.sw_if_index else 0xffffffff, epg_id=self.epg if self.epg else 0xffffffff, is_ip6=self.is_ip6) self._test.registry.register(self, self._test.logger) def remove_vpp_config(self): self._test.vapi.gbp_subnet_add_del( 0, self.table_id, self.is_internal, self.address_n, self.address_len, is_ip6=self.is_ip6) def __str__(self): return self.object_id() def object_id(self): return "gbp-subnet;[%d:%s/%d]" % (self.table_id, self.address, self.address_len) d
# Copyright (c) 2016 Cisco Systems, Inc.
# 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.
vppplugins_LTLIBRARIES += ixge_plugin.la
ixge_plugin_la_SOURCES = ixge/ixge.c
noinst_HEADERS += ixge/ixge.h
# vi:syntax=automake