include ether type in cpu package
This commit is contained in:
parent
440782c569
commit
60a3c8d8c5
3 changed files with 13 additions and 20 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue