From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 2A7B62BF8 for ; Wed, 20 Apr 2016 03:07:23 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 19 Apr 2016 18:07:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,507,1455004800"; d="scan'208";a="936043971" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga001.jf.intel.com with ESMTP; 19 Apr 2016 18:07:22 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id u3K17KFO026166; Wed, 20 Apr 2016 09:07:20 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id u3K17H8p009580; Wed, 20 Apr 2016 09:07:19 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id u3K17H45009576; Wed, 20 Apr 2016 09:07:17 +0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Wed, 20 Apr 2016 09:07:16 +0800 Message-Id: <1461114436-9544-1-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dts] [PATCH] framework packet: support configure multiple layers X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Apr 2016 01:07:24 -0000 Add new function config_layers in packet module which support configure multiple layers in one function. Raw content will be in hexadecimal format, it will be easier for configuration. Signed-off-by: Marvin Liu diff --git a/framework/packet.py b/framework/packet.py index 2f3bf53..42ac4a5 100755 --- a/framework/packet.py +++ b/framework/packet.py @@ -60,16 +60,15 @@ from scapy.route import * from scapy.packet import bind_layers, Raw from scapy.sendrecv import sendp - # load extension layers +exec_file = os.path.realpath(__file__) +DTS_PATH = exec_file.replace('/framework/packet.py', '') +DEP_FOLDER = DTS_PATH + '/dep' +sys.path.append(DEP_FOLDER) + from vxlan import Vxlan -bind_layers(UDP, Vxlan, dport=4789) -bind_layers(Vxlan, Ether) from nvgre import NVGRE, IPPROTO_NVGRE -bind_layers(IP, NVGRE, proto=IPPROTO_NVGRE) -bind_layers(NVGRE, Ether) from lldp import LLDP, LLDPManagementAddress -bind_layers(Ether, LLDP, type=0x88cc) # packet generator type should be configured later PACKETGEN = "scapy" @@ -269,8 +268,8 @@ class scapy(object): def raw(self, payload=None): if payload is not None: self.pkt[Raw].load = '' - for load in payload: - self.pkt[Raw].load += '%c' % int(load, 16) + for hex1, hex2 in payload: + self.pkt[Raw].load += struct.pack("=B", int('%s%s' %(hex1, hex2), 16)) def vxlan(self, vni=0): self.pkt[Vxlan].vni = vni @@ -534,16 +533,29 @@ class Packet(object): idx = self.pkt_layers.index(layer) except Exception as e: print "INVALID LAYER ID %s" % layer - return -1 + return False if self.check_layer_config(layer, config) is False: - return -1 + return False layer_conf = getattr(self, "_config_layer_%s" % layer) setattr(self, 'configured_layer_%s' % layer, True) return layer_conf(config) + def config_layers(self, layers=None): + """ + Configure packet with multi configurations + """ + for layer in layers: + name, config = layer + if name not in self.pkt_layers: + print "[%s] is missing in packet!!!" % name + raise + if self.config_layer(name, config) is False: + print "[%s] failed to configure!!!" % name + raise + def _config_layer_ether(self, config): return self.pktgen.ether(**config) @@ -767,3 +779,13 @@ if __name__ == "__main__": pkt.config_layer('udp', {'src': 4789, 'dst': 4789, 'chksum': 0x1111}) pkt.config_layer('vxlan', {'vni': 2}) pkt.config_layer('raw', {'payload': ['58'] * 18}) + pkt.send_pkt(tx_port='lo') + + pkt = Packet() + pkt.assign_layers(['ether', 'dot1q', 'ipv4', 'udp', + 'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw']) + # config packet + pkt.config_layers([('ether', {'dst': '00:11:22:33:44:55'}), ('ipv4', {'dst': '1.1.1.1'}), + ('vxlan', {'vni': 2}), ('raw', {'payload': ['01'] * 18})]) + + pkt.send_pkt(tx_port='lo') -- 1.9.3