include ether type in cpu package

This commit is contained in:
Nico Schottelius 2019-03-04 18:05:56 +01:00
parent 440782c569
commit 60a3c8d8c5
3 changed files with 13 additions and 20 deletions

View file

@ -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:

View file

@ -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

View file

@ -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;
}
}
}