From ea1873c14c70916ad4c304ac3f2560bfaca7195d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 4 Mar 2019 16:23:28 +0100 Subject: [PATCH] Use types for signalling expected action --- p4app/controller.py | 15 ++++++++++++--- p4src/headers.p4 | 16 ++++++++++++---- p4src/parsers.p4 | 4 ++++ p4src/static-mapping.p4 | 10 +++++----- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/p4app/controller.py b/p4app/controller.py index ab78600..e8e9c30 100644 --- a/p4app/controller.py +++ b/p4app/controller.py @@ -27,7 +27,10 @@ log = logging.getLogger("main") class CpuHeader(Packet): name = 'CpuPacket' - fields_desc = [BitField('ingress_port', 0, 16)] + fields_desc = [ + BitField('task',0,8) + BitField('ingress_port', 0, 16) + ] class L2Controller(object): @@ -35,6 +38,12 @@ class L2Controller(object): # Command line mapping self.modes = ['base', 'router'] + self.task = { + 'ICMP6_NS': 1, + 'ICMP6_GENERAL': 2, + 'DEBUG': 3 + } + self.info={} self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104") @@ -158,8 +167,8 @@ class L2Controller(object): for v6addr in self.v6_addresses[self.mode]: icmp6_addr = self.gen_ndp_multicast_addr(v6addr) - self.controller.table_add("v6_addresses", "controller_reply", [str(v6addr)]) - self.controller.table_add("v6_addresses", "controller_reply", [str(icmp6_addr)]) + self.controller.table_add("v6_addresses", "controller_reply", [str(self.task['ICMP6_GENERAL'])], [str(v6addr)]) + self.controller.table_add("v6_addresses", "controller_reply", [str(self.task['ICMP6_NS'])], [str(icmp6_addr)]) def config_hosts(self): """ Assumptions: diff --git a/p4src/headers.p4 b/p4src/headers.p4 index fb45d31..024eced 100644 --- a/p4src/headers.p4 +++ b/p4src/headers.p4 @@ -8,8 +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; const bit<16> TYPE_IPV4 = 0x0800; @@ -31,6 +32,10 @@ const bit<8> ICMP6_NS = 135; const bit<8> ICMP6_NA = 136; +const task_t TASK_ICMP6_NS = 1; +const task_t TASK_ICMP6_GENERAL = 2; +const task_t TASK_DEBUG = 3; + header ethernet_t { mac_addr_t dst_addr; @@ -106,6 +111,10 @@ header icmp_t { bit<32> rest; } +header cpu_t { + port_t ingress_port; + task_t task; +} struct headers { ethernet_t ethernet; @@ -115,12 +124,11 @@ struct headers { udp_t udp; icmp6_t icmp6; icmp_t icmp; + cpu_t cpu; } struct metadata { - bit<16> tcp_length; - bit<16> ethertype; /* we use this, if we are cloning */ - bit<1> ether_modified; + task_t task; } #endif \ No newline at end of file diff --git a/p4src/parsers.p4 b/p4src/parsers.p4 index 6f6f768..1c7cfd4 100644 --- a/p4src/parsers.p4 +++ b/p4src/parsers.p4 @@ -75,6 +75,10 @@ parser MyParser(packet_in packet, control MyDeparser(packet_out packet, in headers hdr) { apply { + /* only if information is sent to the controller */ + packet.emit(hdr.cpu); + + /* always */ packet.emit(hdr.ethernet); /* either */ diff --git a/p4src/static-mapping.p4 b/p4src/static-mapping.p4 index a61eaf3..3b8d39e 100644 --- a/p4src/static-mapping.p4 +++ b/p4src/static-mapping.p4 @@ -27,12 +27,12 @@ control MyIngress(inout headers hdr, } action controller_debug() { - meta.ether_modified = 1; - meta.ethertype = TYPE_DEBUG; + meta.task = TASK_DEBUG; clone3(CloneType.I2E, 100, meta); } - action controller_reply() { + action controller_reply(task_t task) { + meta.task = task; clone3(CloneType.I2E, 100, meta); } @@ -203,7 +203,8 @@ control MyEgress(inout headers hdr, apply { // ingress clone if (standard_metadata.instance_type == 1 && meta.ether_modified == 1){ - hdr.ethernet.ethertype = meta.ethertype; + hdr.cpu.setValid(); + hdr.cpu.task = meta.task; } } } @@ -226,7 +227,6 @@ MyDeparser() // hdr.tcp.setValid(); - // hdr.cpu.setValid(); // hdr.cpu.srcAddr = hdr.ethernet.srcAddr; // hdr.cpu.ingress_port = (bit<16>)meta.ingress_port;