From 60a3c8d8c56326e129e0444a37cc731eddc5ca90 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 4 Mar 2019 18:05:56 +0100 Subject: [PATCH] include ether type in cpu package --- p4app/controller.py | 21 +++++---------------- p4src/headers.p4 | 8 +++++--- p4src/static-mapping.p4 | 4 +++- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/p4app/controller.py b/p4app/controller.py index 9bfd1ee..6734532 100644 --- a/p4app/controller.py +++ b/p4app/controller.py @@ -10,6 +10,7 @@ from scapy.all import sniff, get_if_list, Ether, get_if_hwaddr, sendp from scapy.all import IP, Raw, IPv6, TCP, TCP_client from scapy.all import Ether, sniff, Packet, BitField, IntEnumField, ShortField from scapy.all import ICMPv6ND_NS +from scapy.data import ETHER_TYPES import sys import re @@ -35,7 +36,8 @@ class CpuHeader(Packet): name = 'CpuPacket' fields_desc = [ IntEnumField('task', 1, cpu_fields ), - ShortField('ingress_port', 0) + ShortField('ingress_port', 0), + XShortEnumField("type", 0x9000, ETHER_TYPES) ] @@ -237,31 +239,18 @@ class L2Controller(object): elif packet.type == 0x86dd: pass elif packet.type == 0x4242: - print("Special handling needed") + log.debug("CPU packet") cpu_header = CpuHeader(packet.payload) print("cpu = {} {}".format(cpu_header.__repr__(), len(cpu_header))) - ether_part = pkg[Ether] # read from cpu header ether_part.type = 0x86dd ether_orig = Ether(src=packet.src, dst=packet.dst, type=0x86dd) - # used to find correct offset = 3 - - # for i in range(1, 32): - # content_orig = packet.load[i:] - # try: - # orig_packet = ether_orig / IPv6(content_orig) - # print("{}: {}".format(i, orig_packet.__repr__())) - - # except Exception as e: - # pass - orig_packet = ether_orig / IPv6(packet.load[3:]) - self.debug_print_pkg(orig_packet) - print("o={}".format(orig_packet.__repr__())) + log.debug("o={}".format(orig_packet.__repr__())) else: diff --git a/p4src/headers.p4 b/p4src/headers.p4 index e638f1b..8afc5ec 100644 --- a/p4src/headers.p4 +++ b/p4src/headers.p4 @@ -8,9 +8,9 @@ typedef bit<48> mac_addr_t; typedef bit<32> ipv4_addr_t; typedef bit<128> ipv6_addr_t; -typedef bit<9> port_t; +typedef bit<9> port_t; typedef bit<16> mcast_t; -typedef bit<8> task_t; +typedef bit<8> task_t; const bit<16> TYPE_IPV4 = 0x0800; @@ -114,6 +114,7 @@ header icmp_t { header cpu_t { port_t ingress_port; task_t task; + bit<16> ethertype; } struct headers { @@ -128,8 +129,9 @@ struct headers { } struct metadata { - bit<16> tcp_length; + port_t ingress_port; task_t task; + bit<16> tcp_length; } #endif \ No newline at end of file diff --git a/p4src/static-mapping.p4 b/p4src/static-mapping.p4 index 203b7fb..498b7bc 100644 --- a/p4src/static-mapping.p4 +++ b/p4src/static-mapping.p4 @@ -203,9 +203,11 @@ control MyEgress(inout headers hdr, apply { // ingress clone if (standard_metadata.instance_type == 1){ - hdr.ethernet.ethertype = TYPE_CPU; hdr.cpu.setValid(); hdr.cpu.task = meta.task; + hdr.cpu.ethertype = hdr.ethernet.ethertype; + + hdr.ethernet.ethertype = TYPE_CPU; } } }