├── .gitignore ├── BibTeX.txt ├── LICENSE ├── README.md ├── install.sh ├── p4-traffictool ├── samples ├── basic_postcards │ ├── basic_postcards.json │ ├── basic_postcards.p4 │ └── output │ │ ├── moongen │ │ ├── basic_postcards_hdr_meta.lua │ │ └── basic_postcards_q_meta.lua │ │ ├── pcapplusplus │ │ ├── basic_postcards_hdr_meta.cpp │ │ ├── basic_postcards_hdr_meta.h │ │ ├── basic_postcards_q_meta.cpp │ │ └── basic_postcards_q_meta.h │ │ ├── scapy │ │ └── basic_postcards.py │ │ └── wireshark │ │ ├── basic_postcards_1_ipv4.lua │ │ ├── basic_postcards_2_udp.lua │ │ ├── basic_postcards_3_hdr_meta.lua │ │ └── init.lua ├── basic_tunnel │ ├── basic_tunnel.json │ ├── basic_tunnel.p4 │ └── output │ │ ├── moongen │ │ └── basic_tunnel_myTunnel.lua │ │ ├── pcapplusplus │ │ ├── basic_tunnel_myTunnel.cpp │ │ └── basic_tunnel_myTunnel.h │ │ ├── scapy │ │ └── basic_tunnel.py │ │ └── wireshark │ │ ├── basic_tunnel_1_myTunnel.lua │ │ ├── basic_tunnel_2_ipv4.lua │ │ └── init.lua ├── hula │ ├── hula.json │ ├── hula.p4 │ └── output │ │ ├── moongen │ │ ├── hula_hula.lua │ │ └── hula_srcRoutes.lua │ │ ├── pcapplusplus │ │ ├── hula_hula.cpp │ │ ├── hula_hula.h │ │ ├── hula_srcRoutes.cpp │ │ └── hula_srcRoutes.h │ │ ├── scapy │ │ └── hula.py │ │ └── wireshark │ │ ├── hula_1_hula.lua │ │ ├── hula_2_srcRoutes.lua │ │ ├── hula_3_ipv4.lua │ │ ├── hula_4_udp.lua │ │ └── init.lua ├── linear_road │ ├── header.p4 │ ├── linear_road.json │ ├── linear_road.p4 │ ├── output │ │ ├── moongen │ │ │ ├── linear_road_accident_alert.lua │ │ │ ├── linear_road_accnt_bal.lua │ │ │ ├── linear_road_accnt_bal_req.lua │ │ │ ├── linear_road_expenditure_report.lua │ │ │ ├── linear_road_expenditure_req.lua │ │ │ ├── linear_road_lr_msg_type.lua │ │ │ ├── linear_road_pos_report.lua │ │ │ ├── linear_road_toll_notification.lua │ │ │ ├── linear_road_travel_estimate.lua │ │ │ └── linear_road_travel_estimate_req.lua │ │ ├── pcapplusplus │ │ │ ├── linear_road_accident_alert.cpp │ │ │ ├── linear_road_accident_alert.h │ │ │ ├── linear_road_accnt_bal.cpp │ │ │ ├── linear_road_accnt_bal.h │ │ │ ├── linear_road_accnt_bal_req.cpp │ │ │ ├── linear_road_accnt_bal_req.h │ │ │ ├── linear_road_expenditure_report.cpp │ │ │ ├── linear_road_expenditure_report.h │ │ │ ├── linear_road_expenditure_req.cpp │ │ │ ├── linear_road_expenditure_req.h │ │ │ ├── linear_road_lr_msg_type.cpp │ │ │ ├── linear_road_lr_msg_type.h │ │ │ ├── linear_road_pos_report.cpp │ │ │ ├── linear_road_pos_report.h │ │ │ ├── linear_road_toll_notification.cpp │ │ │ ├── linear_road_toll_notification.h │ │ │ ├── linear_road_travel_estimate.cpp │ │ │ ├── linear_road_travel_estimate.h │ │ │ ├── linear_road_travel_estimate_req.cpp │ │ │ └── linear_road_travel_estimate_req.h │ │ ├── scapy │ │ │ └── linear_road.py │ │ └── wireshark │ │ │ ├── init.lua │ │ │ ├── linear_road_10_expenditure_report.lua │ │ │ ├── linear_road_11_travel_estimate_req.lua │ │ │ ├── linear_road_12_travel_estimate.lua │ │ │ ├── linear_road_1_ipv4.lua │ │ │ ├── linear_road_2_udp.lua │ │ │ ├── linear_road_3_lr_msg_type.lua │ │ │ ├── linear_road_4_pos_report.lua │ │ │ ├── linear_road_5_accnt_bal_req.lua │ │ │ ├── linear_road_6_toll_notification.lua │ │ │ ├── linear_road_7_accident_alert.lua │ │ │ ├── linear_road_8_accnt_bal.lua │ │ │ └── linear_road_9_expenditure_req.lua │ └── parser.p4 ├── mri │ ├── mri.json │ ├── mri.p4 │ └── output │ │ ├── moongen │ │ ├── mri_ipv4_option.lua │ │ ├── mri_mri.lua │ │ └── mri_swids.lua │ │ ├── pcapplusplus │ │ ├── mri_ipv4_option.cpp │ │ ├── mri_ipv4_option.h │ │ ├── mri_mri.cpp │ │ ├── mri_mri.h │ │ ├── mri_swids.cpp │ │ └── mri_swids.h │ │ ├── scapy │ │ └── mri.py │ │ └── wireshark │ │ ├── init.lua │ │ ├── mri_1_ipv4.lua │ │ ├── mri_2_ipv4_option.lua │ │ ├── mri_3_mri.lua │ │ └── mri_4_swids.lua ├── netcache │ ├── .Rhistory │ ├── cache.p4 │ ├── ethernet.p4 │ ├── heavy_hitter.p4 │ ├── includes │ │ ├── checksum.p4 │ │ ├── defines.p4 │ │ ├── headers.p4 │ │ └── parsers.p4 │ ├── ipv4.p4 │ ├── netcache.json │ ├── netcache.p4 │ ├── output │ │ ├── moongen │ │ │ ├── netcache_nc_hdr.lua │ │ │ ├── netcache_nc_load.lua │ │ │ ├── netcache_nc_value_1.lua │ │ │ ├── netcache_nc_value_2.lua │ │ │ ├── netcache_nc_value_3.lua │ │ │ ├── netcache_nc_value_4.lua │ │ │ ├── netcache_nc_value_5.lua │ │ │ ├── netcache_nc_value_6.lua │ │ │ ├── netcache_nc_value_7.lua │ │ │ └── netcache_nc_value_8.lua │ │ ├── pcapplusplus │ │ │ ├── netcache_nc_hdr.cpp │ │ │ ├── netcache_nc_hdr.h │ │ │ ├── netcache_nc_load.cpp │ │ │ ├── netcache_nc_load.h │ │ │ ├── netcache_nc_value_1.cpp │ │ │ ├── netcache_nc_value_1.h │ │ │ ├── netcache_nc_value_2.cpp │ │ │ ├── netcache_nc_value_2.h │ │ │ ├── netcache_nc_value_3.cpp │ │ │ ├── netcache_nc_value_3.h │ │ │ ├── netcache_nc_value_4.cpp │ │ │ ├── netcache_nc_value_4.h │ │ │ ├── netcache_nc_value_5.cpp │ │ │ ├── netcache_nc_value_5.h │ │ │ ├── netcache_nc_value_6.cpp │ │ │ ├── netcache_nc_value_6.h │ │ │ ├── netcache_nc_value_7.cpp │ │ │ ├── netcache_nc_value_7.h │ │ │ ├── netcache_nc_value_8.cpp │ │ │ └── netcache_nc_value_8.h │ │ ├── scapy │ │ │ └── netcache.py │ │ └── wireshark │ │ │ ├── init.lua │ │ │ ├── netcache_1_ipv4.lua │ │ │ ├── netcache_2_tcp.lua │ │ │ ├── netcache_3_udp.lua │ │ │ ├── netcache_4_nc_hdr.lua │ │ │ └── netcache_5_nc_load.lua │ └── value.p4 ├── netchain │ ├── includes │ │ ├── checksum.p4 │ │ ├── defines.p4 │ │ ├── headers.p4 │ │ └── parsers.p4 │ ├── netchain.json │ ├── netchain.p4 │ ├── output │ │ ├── moongen │ │ │ ├── netchain_nc_hdr.lua │ │ │ └── netchain_overlay.lua │ │ ├── pcapplusplus │ │ │ ├── netchain_nc_hdr.cpp │ │ │ ├── netchain_nc_hdr.h │ │ │ ├── netchain_overlay.cpp │ │ │ └── netchain_overlay.h │ │ ├── scapy │ │ │ └── netchain.py │ │ └── wireshark │ │ │ ├── init.lua │ │ │ ├── netchain_1_ipv4.lua │ │ │ ├── netchain_2_tcp.lua │ │ │ ├── netchain_3_udp.lua │ │ │ ├── netchain_4_overlay.lua │ │ │ └── netchain_5_nc_hdr.lua │ └── routing.p4 ├── p4paxos │ ├── includes │ │ ├── headers.p4 │ │ ├── parser.p4 │ │ ├── paxos_headers.p4 │ │ └── paxos_parser.p4 │ ├── l2_control.p4 │ ├── output │ │ ├── moongen │ │ │ └── paxos_acceptor_paxos.lua │ │ ├── pcapplusplus │ │ │ ├── paxos_acceptor_paxos.cpp │ │ │ └── paxos_acceptor_paxos.h │ │ ├── scapy │ │ │ └── paxos_acceptor.py │ │ └── wireshark │ │ │ ├── init.lua │ │ │ ├── paxos_acceptor_1_ipv4.lua │ │ │ ├── paxos_acceptor_2_udp.lua │ │ │ └── paxos_acceptor_3_paxos.lua │ ├── paxos_acceptor.json │ ├── paxos_acceptor.p4 │ └── paxos_coordinator.p4 ├── qmetadata │ ├── includes │ │ ├── headers.p4 │ │ └── parser.p4 │ ├── output │ │ ├── moongen │ │ │ ├── qmetadata_q_meta.lua │ │ │ └── qmetadata_snapshot.lua │ │ ├── pcapplusplus │ │ │ ├── qmetadata_q_meta.cpp │ │ │ ├── qmetadata_q_meta.h │ │ │ ├── qmetadata_snapshot.cpp │ │ │ └── qmetadata_snapshot.h │ │ ├── scapy │ │ │ └── qmetadata.py │ │ └── wireshark │ │ │ ├── init.lua │ │ │ ├── qmetadata_1_ipv4.lua │ │ │ ├── qmetadata_2_udp.lua │ │ │ ├── qmetadata_3_q_meta.lua │ │ │ └── qmetadata_4_snapshot.lua │ ├── qmetadata.json │ └── qmetadata.p4 ├── sources.txt └── src_routing │ ├── output │ ├── moongen │ │ └── src_routing_srcRoutes.lua │ ├── pcapplusplus │ │ ├── src_routing_srcRoutes.cpp │ │ └── src_routing_srcRoutes.h │ ├── scapy │ │ └── src_routing.py │ └── wireshark │ │ ├── init.lua │ │ ├── src_routing_1_srcRoutes.lua │ │ └── src_routing_2_ipv4.lua │ ├── src_routing.json │ └── src_routing.p4 ├── src ├── DissectTrafficLua.py ├── DissectTrafficPcap.py ├── GenTrafficMoonGen.py ├── GenTrafficScapy.py ├── common.py └── config.py ├── templates ├── bitfields_def.lua ├── template.p4 ├── templateMoonGen.lua ├── uint24_t.h ├── uint40_t.h └── uint48_t.h ├── tests └── runsamples.sh └── uninstall.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.p4i 3 | *.p4rt 4 | tests/*.pcap 5 | *.pcap 6 | docs/_site/* 7 | docs/.jekyll-cache/* 8 | docs/.sass-cache/* 9 | -------------------------------------------------------------------------------- /BibTeX.txt: -------------------------------------------------------------------------------- 1 | @inproceedings{jindal2019p4traffictool, 2 | title={P4TrafficTool: Automated Code Generation for P4 Traffic Generators and Analyzers}, 3 | author={Jindal, Deepanshu and Joshi, Raj and Leong, Ben}, 4 | booktitle={Proceedings of ACM Symposium on SDN Research}, 5 | year={2019} 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 National University of Singapore - Systems and Networking Laboratory 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo cp p4-traffictool /usr/bin/ 4 | 5 | sudo mkdir -p /usr/share/p4-traffictool/src 6 | sudo mkdir -p /usr/share/p4-traffictool/templates 7 | sudo cp src/*.py /usr/share/p4-traffictool/src/ 8 | sudo cp templates/* /usr/share/p4-traffictool/templates/ 9 | -------------------------------------------------------------------------------- /samples/basic_postcards/output/pcapplusplus/basic_postcards_hdr_meta.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'hdr_meta' 2 | 3 | #ifndef P4_HDR_META_LAYER 4 | #define P4_HDR_META_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct hdr_metahdr{ 20 | uint48_t mac_dstAddr; 21 | uint48_t mac_srcAddr; 22 | uint32_t ip_srcAddr; 23 | uint32_t ip_dstAddr; 24 | uint8_t ip_protocol; 25 | }; 26 | 27 | #pragma pack(pop) 28 | class Hdr_metaLayer: public Layer{ 29 | public: 30 | Hdr_metaLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_HDR_META;} 31 | Hdr_metaLayer(){ 32 | m_DataLen = sizeof(hdr_metahdr); 33 | m_Data = new uint8_t[m_DataLen]; 34 | memset(m_Data, 0, m_DataLen); 35 | m_Protocol = P4_HDR_META; 36 | } 37 | 38 | // Getters and Setters for fields 39 | uint64_t getMac_dstaddr(); 40 | void setMac_dstaddr(uint64_t value); 41 | uint64_t getMac_srcaddr(); 42 | void setMac_srcaddr(uint64_t value); 43 | uint32_t getIp_srcaddr(); 44 | void setIp_srcaddr(uint32_t value); 45 | uint32_t getIp_dstaddr(); 46 | void setIp_dstaddr(uint32_t value); 47 | uint8_t getIp_protocol(); 48 | void setIp_protocol(uint8_t value); 49 | 50 | inline hdr_metahdr* getHdr_metaHeader() { return (hdr_metahdr*)m_Data; } 51 | 52 | void parseNextLayer(); 53 | 54 | inline size_t getHeaderLen() { return sizeof(hdr_metahdr); } 55 | 56 | void computeCalculateFields() {} 57 | 58 | std::string toString(); 59 | 60 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 61 | 62 | }; 63 | } 64 | #endif -------------------------------------------------------------------------------- /samples/basic_postcards/output/pcapplusplus/basic_postcards_q_meta.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleQ_metaLayer 2 | 3 | #include "basic_postcards_q_meta.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Q_metaLayer::getEnq_qdepth(){ 13 | uint24_t enq_qdepth; 14 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 15 | UINT24_HTON(enq_qdepth,hdrdata->enq_qdepth); 16 | uint32_t return_val = UINT24_GET(enq_qdepth); 17 | return return_val; 18 | } 19 | 20 | void Q_metaLayer::setEnq_qdepth(uint32_t value){ 21 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 22 | uint24_t value_set; 23 | UINT24_SET(value_set, value); 24 | UINT24_HTON(hdrdata->enq_qdepth, value_set); 25 | } 26 | uint32_t Q_metaLayer::getDeq_qdepth(){ 27 | uint24_t deq_qdepth; 28 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 29 | UINT24_HTON(deq_qdepth,hdrdata->deq_qdepth); 30 | uint32_t return_val = UINT24_GET(deq_qdepth); 31 | return return_val; 32 | } 33 | 34 | void Q_metaLayer::setDeq_qdepth(uint32_t value){ 35 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 36 | uint24_t value_set; 37 | UINT24_SET(value_set, value); 38 | UINT24_HTON(hdrdata->deq_qdepth, value_set); 39 | } 40 | uint32_t Q_metaLayer::getDeq_timedelta(){ 41 | uint32_t deq_timedelta; 42 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 43 | deq_timedelta = htonl(hdrdata->deq_timedelta); 44 | return deq_timedelta; 45 | } 46 | 47 | void Q_metaLayer::setDeq_timedelta(uint32_t value){ 48 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 49 | hdrdata->deq_timedelta = htonl(value); 50 | } 51 | uint32_t Q_metaLayer::getEnq_timestamp(){ 52 | uint32_t enq_timestamp; 53 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 54 | enq_timestamp = htonl(hdrdata->enq_timestamp); 55 | return enq_timestamp; 56 | } 57 | 58 | void Q_metaLayer::setEnq_timestamp(uint32_t value){ 59 | q_metahdr* hdrdata = (q_metahdr*)m_Data; 60 | hdrdata->enq_timestamp = htonl(value); 61 | } 62 | void Q_metaLayer::parseNextLayer(){ 63 | if (m_DataLen <= sizeof(q_metahdr)) 64 | return; 65 | 66 | } 67 | 68 | std::string Q_metaLayer::toString(){ return ""; } 69 | 70 | } -------------------------------------------------------------------------------- /samples/basic_postcards/output/pcapplusplus/basic_postcards_q_meta.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'q_meta' 2 | 3 | #ifndef P4_Q_META_LAYER 4 | #define P4_Q_META_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct q_metahdr{ 20 | uint24_t enq_qdepth; 21 | uint24_t deq_qdepth; 22 | uint32_t deq_timedelta; 23 | uint32_t enq_timestamp; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Q_metaLayer: public Layer{ 28 | public: 29 | Q_metaLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_Q_META;} 30 | Q_metaLayer(){ 31 | m_DataLen = sizeof(q_metahdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_Q_META; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getEnq_qdepth(); 39 | void setEnq_qdepth(uint32_t value); 40 | uint32_t getDeq_qdepth(); 41 | void setDeq_qdepth(uint32_t value); 42 | uint32_t getDeq_timedelta(); 43 | void setDeq_timedelta(uint32_t value); 44 | uint32_t getEnq_timestamp(); 45 | void setEnq_timestamp(uint32_t value); 46 | 47 | inline q_metahdr* getQ_metaHeader() { return (q_metahdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(q_metahdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/basic_postcards/output/scapy/basic_postcards.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class Hdr_meta(Packet): 5 | name = 'hdr_meta' 6 | fields_desc = [ 7 | XBitField('mac_dstAddr', 0, 48), 8 | XBitField('mac_srcAddr', 0, 48), 9 | XIntField('ip_srcAddr', 0), 10 | XIntField('ip_dstAddr', 0), 11 | XByteField('ip_protocol', 0), 12 | ] 13 | class Q_meta(Packet): 14 | name = 'q_meta' 15 | fields_desc = [ 16 | XBitField('enq_qdepth', 0, 24), 17 | XBitField('deq_qdepth', 0, 24), 18 | XIntField('deq_timedelta', 0), 19 | XIntField('enq_timestamp', 0), 20 | ] 21 | 22 | ## remaining bindings 23 | bind_layers(Ether, IP, type=0x0800) 24 | bind_layers(IP, UDP, proto=0x11) 25 | bind_layers(UDP, Hdr_meta, dport=0x270f) 26 | 27 | ##packet_list 28 | possible_packets_ = [ 29 | (Ether()), 30 | (Ether()/IP()), 31 | (Ether()/IP()/UDP()), 32 | (Ether()/IP()/UDP()/Hdr_meta()) 33 | ] 34 | -------------------------------------------------------------------------------- /samples/basic_postcards/output/wireshark/basic_postcards_2_udp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_udp = Proto('p4_udp','P4_UDPProtocol') 3 | 4 | -- protocol fields 5 | local p4_udp_src_port = ProtoField.string('p4_udp.src_port','src_port') 6 | local p4_udp_dst_port = ProtoField.string('p4_udp.dst_port','dst_port') 7 | local p4_udp_len = ProtoField.string('p4_udp.len','len') 8 | local p4_udp_checksum = ProtoField.string('p4_udp.checksum','checksum') 9 | p4_udp.fields = {p4_udp_src_port, p4_udp_dst_port, p4_udp_len, p4_udp_checksum} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_udp.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_UDP' 15 | local subtree = tree:add(p4_udp,buffer(),'P4_UDP Protocol Data') 16 | subtree:add(p4_udp_src_port,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_udp_dst_port,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_udp_len,tostring(buffer(4,2):bitfield(0,16))) 19 | subtree:add(p4_udp_checksum,tostring(buffer(6,2):bitfield(0,16))) 20 | local mydissectortable = DissectorTable.get('p4_udp.dst_port') 21 | mydissectortable:try(buffer(2,2):bitfield(0,16), buffer:range(8):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_udp.dst_port','P4_UDP.DST_PORT',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('p4_ipv4.protocol') 32 | my_table:add(0x11,p4_udp) 33 | -------------------------------------------------------------------------------- /samples/basic_postcards/output/wireshark/basic_postcards_3_hdr_meta.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_hdr_meta = Proto('p4_hdr_meta','P4_HDR_METAProtocol') 3 | 4 | -- protocol fields 5 | local p4_hdr_meta_mac_dstAddr = ProtoField.string('p4_hdr_meta.mac_dstAddr','mac_dstAddr') 6 | local p4_hdr_meta_mac_srcAddr = ProtoField.string('p4_hdr_meta.mac_srcAddr','mac_srcAddr') 7 | local p4_hdr_meta_ip_srcAddr = ProtoField.string('p4_hdr_meta.ip_srcAddr','ip_srcAddr') 8 | local p4_hdr_meta_ip_dstAddr = ProtoField.string('p4_hdr_meta.ip_dstAddr','ip_dstAddr') 9 | local p4_hdr_meta_ip_protocol = ProtoField.string('p4_hdr_meta.ip_protocol','ip_protocol') 10 | p4_hdr_meta.fields = {p4_hdr_meta_mac_dstAddr, p4_hdr_meta_mac_srcAddr, p4_hdr_meta_ip_srcAddr, p4_hdr_meta_ip_dstAddr, p4_hdr_meta_ip_protocol} 11 | 12 | 13 | -- protocol dissector function 14 | function p4_hdr_meta.dissector(buffer,pinfo,tree) 15 | pinfo.cols.protocol = 'P4_HDR_META' 16 | local subtree = tree:add(p4_hdr_meta,buffer(),'P4_HDR_META Protocol Data') 17 | subtree:add(p4_hdr_meta_mac_dstAddr,tostring(buffer(0,6):bitfield(0,48))) 18 | subtree:add(p4_hdr_meta_mac_srcAddr,tostring(buffer(6,6):bitfield(0,48))) 19 | subtree:add(p4_hdr_meta_ip_srcAddr,tostring(buffer(12,4):bitfield(0,32))) 20 | subtree:add(p4_hdr_meta_ip_dstAddr,tostring(buffer(16,4):bitfield(0,32))) 21 | subtree:add(p4_hdr_meta_ip_protocol,tostring(buffer(20,1):bitfield(0,8))) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | 29 | -- No table required 30 | 31 | -- protocol registration 32 | my_table = DissectorTable.get('p4_udp.dst_port') 33 | my_table:add(0x270f,p4_hdr_meta) 34 | -------------------------------------------------------------------------------- /samples/basic_postcards/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/basic_postcards/output/wireshark/basic_postcards_1_ipv4.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/basic_postcards/output/wireshark/basic_postcards_2_udp.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/basic_postcards/output/wireshark/basic_postcards_3_hdr_meta.lua') 4 | -------------------------------------------------------------------------------- /samples/basic_tunnel/output/pcapplusplus/basic_tunnel_myTunnel.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleMytunnelLayer 2 | 3 | #include "basic_tunnel_myTunnel.h" 4 | #include "basic_tunnel_ipv4.h" 5 | #include "PayloadLayer.h" 6 | #include "IpUtils.h" 7 | #include "Logger.h" 8 | #include 9 | #include 10 | #include 11 | 12 | namespace pcpp{ 13 | uint16_t MytunnelLayer::getProto_id(){ 14 | uint16_t proto_id; 15 | mytunnelhdr* hdrdata = (mytunnelhdr*)m_Data; 16 | proto_id = htons(hdrdata->proto_id); 17 | return proto_id; 18 | } 19 | 20 | void MytunnelLayer::setProto_id(uint16_t value){ 21 | mytunnelhdr* hdrdata = (mytunnelhdr*)m_Data; 22 | hdrdata->proto_id = htons(value); 23 | } 24 | uint16_t MytunnelLayer::getDst_id(){ 25 | uint16_t dst_id; 26 | mytunnelhdr* hdrdata = (mytunnelhdr*)m_Data; 27 | dst_id = htons(hdrdata->dst_id); 28 | return dst_id; 29 | } 30 | 31 | void MytunnelLayer::setDst_id(uint16_t value){ 32 | mytunnelhdr* hdrdata = (mytunnelhdr*)m_Data; 33 | hdrdata->dst_id = htons(value); 34 | } 35 | void MytunnelLayer::parseNextLayer(){ 36 | if (m_DataLen <= sizeof(mytunnelhdr)) 37 | return; 38 | 39 | uint16_t proto_id = MytunnelLayer::getProto_id(); 40 | m_NextLayer = new Ipv4Layer(m_Data+sizeof(mytunnelhdr), m_DataLen - sizeof(mytunnelhdr), this, m_Packet); 41 | else if (proto_id == 0x0800) 42 | m_NextLayer = new Ipv4Layer(m_Data+sizeof(mytunnelhdr), m_DataLen - sizeof(mytunnelhdr), this, m_Packet); 43 | else 44 | m_NextLayer = new PayloadLayer(m_Data + sizeof(mytunnelhdr), m_DataLen - sizeof(mytunnelhdr), this, m_Packet); 45 | } 46 | 47 | std::string MytunnelLayer::toString(){ return ""; } 48 | 49 | } -------------------------------------------------------------------------------- /samples/basic_tunnel/output/pcapplusplus/basic_tunnel_myTunnel.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'myTunnel' 2 | 3 | #ifndef P4_MYTUNNEL_LAYER 4 | #define P4_MYTUNNEL_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct mytunnelhdr{ 20 | uint16_t proto_id; 21 | uint16_t dst_id; 22 | }; 23 | 24 | #pragma pack(pop) 25 | class MytunnelLayer: public Layer{ 26 | public: 27 | MytunnelLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_MYTUNNEL;} 28 | MytunnelLayer(){ 29 | m_DataLen = sizeof(mytunnelhdr); 30 | m_Data = new uint8_t[m_DataLen]; 31 | memset(m_Data, 0, m_DataLen); 32 | m_Protocol = P4_MYTUNNEL; 33 | } 34 | 35 | // Getters and Setters for fields 36 | uint16_t getProto_id(); 37 | void setProto_id(uint16_t value); 38 | uint16_t getDst_id(); 39 | void setDst_id(uint16_t value); 40 | 41 | inline mytunnelhdr* getMytunnelHeader() { return (mytunnelhdr*)m_Data; } 42 | 43 | void parseNextLayer(); 44 | 45 | inline size_t getHeaderLen() { return sizeof(mytunnelhdr); } 46 | 47 | void computeCalculateFields() {} 48 | 49 | std::string toString(); 50 | 51 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 52 | 53 | }; 54 | } 55 | #endif -------------------------------------------------------------------------------- /samples/basic_tunnel/output/scapy/basic_tunnel.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class MyTunnel(Packet): 5 | name = 'myTunnel' 6 | fields_desc = [ 7 | XShortField('proto_id', 0), 8 | XShortField('dst_id', 0), 9 | ] 10 | 11 | def guess_payload_class(self, payload): 12 | if (self.proto_id == 0x0800): 13 | return Ip 14 | else: 15 | return Packet.guess_payload_class(self, payload) 16 | 17 | 18 | ## remaining bindings 19 | bind_layers(Ether, MyTunnel, type=0x1212) 20 | bind_layers(Ether, IP, type=0x0800) 21 | 22 | ##packet_list 23 | possible_packets_ = [ 24 | (Ether()), 25 | (Ether()/MyTunnel()), 26 | (Ether()/IP()), 27 | (Ether()/MyTunnel()/IP()) 28 | ] 29 | -------------------------------------------------------------------------------- /samples/basic_tunnel/output/wireshark/basic_tunnel_1_myTunnel.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_mytunnel = Proto('p4_mytunnel','P4_MYTUNNELProtocol') 3 | 4 | -- protocol fields 5 | local p4_mytunnel_proto_id = ProtoField.string('p4_mytunnel.proto_id','proto_id') 6 | local p4_mytunnel_dst_id = ProtoField.string('p4_mytunnel.dst_id','dst_id') 7 | p4_mytunnel.fields = {p4_mytunnel_proto_id, p4_mytunnel_dst_id} 8 | 9 | 10 | -- protocol dissector function 11 | function p4_mytunnel.dissector(buffer,pinfo,tree) 12 | pinfo.cols.protocol = 'P4_MYTUNNEL' 13 | local subtree = tree:add(p4_mytunnel,buffer(),'P4_MYTUNNEL Protocol Data') 14 | subtree:add(p4_mytunnel_proto_id,tostring(buffer(0,2):bitfield(0,16))) 15 | subtree:add(p4_mytunnel_dst_id,tostring(buffer(2,2):bitfield(0,16))) 16 | local mydissectortable = DissectorTable.get('p4_myTunnel.proto_id') 17 | mydissectortable:try(buffer(0,2):bitfield(0,16), buffer:range(4):tvb(),pinfo,tree) 18 | 19 | end 20 | 21 | print( (require 'debug').getinfo(1).source ) 22 | 23 | -- creation of table for next layer(if required) 24 | local newdissectortable = DissectorTable.new('p4_myTunnel.proto_id','P4_MYTUNNEL.PROTO_ID',ftypes.STRING) 25 | 26 | -- protocol registration 27 | my_table = DissectorTable.get('ethertype') 28 | my_table:add(0x1212,p4_mytunnel) 29 | -------------------------------------------------------------------------------- /samples/basic_tunnel/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/basic_tunnel/output/wireshark/basic_tunnel_1_myTunnel.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/basic_tunnel/output/wireshark/basic_tunnel_2_ipv4.lua') 3 | -------------------------------------------------------------------------------- /samples/hula/output/pcapplusplus/hula_hula.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleHulaLayer 2 | 3 | #include "hula_hula.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint8_t HulaLayer::getDir(){ 13 | uint8_t dir; 14 | hulahdr* hdrdata = (hulahdr*)m_Data; 15 | dir = (hdrdata->dir); 16 | return dir; 17 | } 18 | 19 | void HulaLayer::setDir(uint8_t value){ 20 | hulahdr* hdrdata = (hulahdr*)m_Data; 21 | hdrdata->dir = (value); 22 | } 23 | uint16_t HulaLayer::getQdepth(){ 24 | uint16_t qdepth; 25 | hulahdr* hdrdata = (hulahdr*)m_Data; 26 | qdepth = htons(hdrdata->qdepth); 27 | return qdepth; 28 | } 29 | 30 | void HulaLayer::setQdepth(uint16_t value){ 31 | hulahdr* hdrdata = (hulahdr*)m_Data; 32 | hdrdata->qdepth = htons(value); 33 | } 34 | uint32_t HulaLayer::getDigest(){ 35 | uint32_t digest; 36 | hulahdr* hdrdata = (hulahdr*)m_Data; 37 | digest = htonl(hdrdata->digest); 38 | return digest; 39 | } 40 | 41 | void HulaLayer::setDigest(uint32_t value){ 42 | hulahdr* hdrdata = (hulahdr*)m_Data; 43 | hdrdata->digest = htonl(value); 44 | } 45 | void HulaLayer::parseNextLayer(){ 46 | if (m_DataLen <= sizeof(hulahdr)) 47 | return; 48 | 49 | } 50 | 51 | std::string HulaLayer::toString(){ return ""; } 52 | 53 | } -------------------------------------------------------------------------------- /samples/hula/output/pcapplusplus/hula_hula.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'hula' 2 | 3 | #ifndef P4_HULA_LAYER 4 | #define P4_HULA_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct hulahdr{ 20 | uint8_t dir; 21 | uint16_t qdepth; 22 | uint32_t digest; 23 | }; 24 | 25 | #pragma pack(pop) 26 | class HulaLayer: public Layer{ 27 | public: 28 | HulaLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_HULA;} 29 | HulaLayer(){ 30 | m_DataLen = sizeof(hulahdr); 31 | m_Data = new uint8_t[m_DataLen]; 32 | memset(m_Data, 0, m_DataLen); 33 | m_Protocol = P4_HULA; 34 | } 35 | 36 | // Getters and Setters for fields 37 | uint8_t getDir(); 38 | void setDir(uint8_t value); 39 | uint16_t getQdepth(); 40 | void setQdepth(uint16_t value); 41 | uint32_t getDigest(); 42 | void setDigest(uint32_t value); 43 | 44 | inline hulahdr* getHulaHeader() { return (hulahdr*)m_Data; } 45 | 46 | void parseNextLayer(); 47 | 48 | inline size_t getHeaderLen() { return sizeof(hulahdr); } 49 | 50 | void computeCalculateFields() {} 51 | 52 | std::string toString(); 53 | 54 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 55 | 56 | }; 57 | } 58 | #endif -------------------------------------------------------------------------------- /samples/hula/output/pcapplusplus/hula_srcRoutes.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleSrcroutesLayer 2 | 3 | #include "hula_srcRoutes.h" 4 | #include "hula_ipv4.h" 5 | #include "hula_srcRoutes.h" 6 | #include "PayloadLayer.h" 7 | #include "IpUtils.h" 8 | #include "Logger.h" 9 | #include 10 | #include 11 | #include 12 | 13 | namespace pcpp{ 14 | uint8_t SrcroutesLayer::getBos(){ 15 | uint8_t bos; 16 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 17 | bos = (hdrdata->bos); 18 | return bos; 19 | } 20 | 21 | void SrcroutesLayer::setBos(uint8_t value){ 22 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 23 | hdrdata->bos = (value); 24 | } 25 | uint16_t SrcroutesLayer::getPort(){ 26 | uint16_t port; 27 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 28 | port = htons(hdrdata->port); 29 | return port; 30 | } 31 | 32 | void SrcroutesLayer::setPort(uint16_t value){ 33 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 34 | hdrdata->port = htons(value); 35 | } 36 | void SrcroutesLayer::parseNextLayer(){ 37 | if (m_DataLen <= sizeof(srcrouteshdr)) 38 | return; 39 | 40 | uint8_t bos = SrcroutesLayer::getBos(); 41 | if (bos == 0x01) 42 | m_NextLayer = new Ipv4Layer(m_Data+sizeof(srcrouteshdr), m_DataLen - sizeof(srcrouteshdr), this, m_Packet); 43 | else if (bos == 0xfa) 44 | m_NextLayer = new SrcroutesLayer(m_Data+sizeof(srcrouteshdr), m_DataLen - sizeof(srcrouteshdr), this, m_Packet); 45 | m_NextLayer = new PayloadLayer(m_Data + sizeof(srcrouteshdr), m_DataLen - sizeof(srcrouteshdr), this, m_Packet); 46 | } 47 | 48 | std::string SrcroutesLayer::toString(){ return ""; } 49 | 50 | } -------------------------------------------------------------------------------- /samples/hula/output/pcapplusplus/hula_srcRoutes.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'srcRoutes' 2 | 3 | #ifndef P4_SRCROUTES_LAYER 4 | #define P4_SRCROUTES_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct srcrouteshdr{ 20 | uint8_t bos; 21 | uint16_t port; 22 | }; 23 | 24 | #pragma pack(pop) 25 | class SrcroutesLayer: public Layer{ 26 | public: 27 | SrcroutesLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_SRCROUTES;} 28 | SrcroutesLayer(){ 29 | m_DataLen = sizeof(srcrouteshdr); 30 | m_Data = new uint8_t[m_DataLen]; 31 | memset(m_Data, 0, m_DataLen); 32 | m_Protocol = P4_SRCROUTES; 33 | } 34 | 35 | // Getters and Setters for fields 36 | uint8_t getBos(); 37 | void setBos(uint8_t value); 38 | uint16_t getPort(); 39 | void setPort(uint16_t value); 40 | 41 | inline srcrouteshdr* getSrcroutesHeader() { return (srcrouteshdr*)m_Data; } 42 | 43 | void parseNextLayer(); 44 | 45 | inline size_t getHeaderLen() { return sizeof(srcrouteshdr); } 46 | 47 | void computeCalculateFields() {} 48 | 49 | std::string toString(); 50 | 51 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 52 | 53 | }; 54 | } 55 | #endif -------------------------------------------------------------------------------- /samples/hula/output/scapy/hula.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class Hula(Packet): 5 | name = 'hula' 6 | fields_desc = [ 7 | XBitField('_pad0', 0, 7), 8 | XBitField('dir', 0, 1), 9 | XBitField('_pad1', 0, 1), 10 | XBitField('qdepth', 0, 15), 11 | XIntField('digest', 0), 12 | ] 13 | #update hdrChecksum over [['ipv4', 'version'], ['ipv4', 'ihl'], ['ipv4', 'diffserv'], ['ipv4', 'totalLen'], ['ipv4', 'identification'], ['ipv4', 'flags'], ['ipv4', 'fragOffset'], ['ipv4', 'ttl'], ['ipv4', 'protocol'], ['ipv4', 'srcAddr'], ['ipv4', 'dstAddr']] using csum16 in post_build method 14 | 15 | class SrcRoutes(Packet): 16 | name = 'srcRoutes' 17 | fields_desc = [ 18 | XBitField('_pad0', 0, 7), 19 | XBitField('bos', 0, 1), 20 | XBitField('_pad1', 0, 1), 21 | XBitField('port', 0, 15), 22 | ] 23 | 24 | def guess_payload_class(self, payload): 25 | if (self.bos == 0x01): 26 | return Ip 27 | elif (self.bos == 0xfa): 28 | return Srcroutes 29 | else: 30 | return Packet.guess_payload_class(self, payload) 31 | 32 | 33 | ## remaining bindings 34 | bind_layers(Ether, Hula, type=0x2345) 35 | bind_layers(Ether, IP, type=0x0800) 36 | bind_layers(IP, UDP, proto=0x11) 37 | 38 | ##packet_list 39 | possible_packets_ = [ 40 | (Ether()), 41 | (Ether()/IP()), 42 | (Ether()/IP()/UDP()), 43 | (Ether()/Hula()/SrcRoutes()/IP()), 44 | (Ether()/Hula()/SrcRoutes()/IP()/UDP()), 45 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/IP()), 46 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 47 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/IP()/UDP()), 48 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()/UDP()), 49 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 50 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 51 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()/UDP()), 52 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 53 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()/UDP()), 54 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()/UDP()), 55 | (Ether()/Hula()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()) 56 | ] 57 | -------------------------------------------------------------------------------- /samples/hula/output/wireshark/hula_1_hula.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_hula = Proto('p4_hula','P4_HULAProtocol') 3 | 4 | -- protocol fields 5 | local p4_hula__pad0 = ProtoField.string('p4_hula._pad0','_pad0') 6 | local p4_hula_dir = ProtoField.string('p4_hula.dir','dir') 7 | local p4_hula__pad1 = ProtoField.string('p4_hula._pad1','_pad1') 8 | local p4_hula_qdepth = ProtoField.string('p4_hula.qdepth','qdepth') 9 | local p4_hula_digest = ProtoField.string('p4_hula.digest','digest') 10 | p4_hula.fields = {p4_hula__pad0, p4_hula_dir, p4_hula__pad1, p4_hula_qdepth, p4_hula_digest} 11 | 12 | 13 | -- protocol dissector function 14 | function p4_hula.dissector(buffer,pinfo,tree) 15 | pinfo.cols.protocol = 'P4_HULA' 16 | local subtree = tree:add(p4_hula,buffer(),'P4_HULA Protocol Data') 17 | subtree:add(p4_hula__pad0,tostring(buffer(0,1):bitfield(0,7))) 18 | subtree:add(p4_hula_dir,tostring(buffer(0,1):bitfield(7,1))) 19 | subtree:add(p4_hula__pad1,tostring(buffer(1,1):bitfield(0,1))) 20 | subtree:add(p4_hula_qdepth,tostring(buffer(1,2):bitfield(1,15))) 21 | subtree:add(p4_hula_digest,tostring(buffer(3,4):bitfield(0,32))) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | 29 | -- No table required 30 | 31 | -- protocol registration 32 | my_table = DissectorTable.get('ethertype') 33 | my_table:add(0x2345,p4_hula) 34 | -------------------------------------------------------------------------------- /samples/hula/output/wireshark/hula_2_srcRoutes.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_srcroutes = Proto('p4_srcroutes','P4_SRCROUTESProtocol') 3 | 4 | -- protocol fields 5 | local p4_srcroutes__pad0 = ProtoField.string('p4_srcroutes._pad0','_pad0') 6 | local p4_srcroutes_bos = ProtoField.string('p4_srcroutes.bos','bos') 7 | local p4_srcroutes__pad1 = ProtoField.string('p4_srcroutes._pad1','_pad1') 8 | local p4_srcroutes_port = ProtoField.string('p4_srcroutes.port','port') 9 | p4_srcroutes.fields = {p4_srcroutes__pad0, p4_srcroutes_bos, p4_srcroutes__pad1, p4_srcroutes_port} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_srcroutes.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_SRCROUTES' 15 | local subtree = tree:add(p4_srcroutes,buffer(),'P4_SRCROUTES Protocol Data') 16 | subtree:add(p4_srcroutes__pad0,tostring(buffer(0,1):bitfield(0,7))) 17 | subtree:add(p4_srcroutes_bos,tostring(buffer(0,1):bitfield(7,1))) 18 | subtree:add(p4_srcroutes__pad1,tostring(buffer(1,1):bitfield(0,1))) 19 | subtree:add(p4_srcroutes_port,tostring(buffer(1,2):bitfield(1,15))) 20 | local mydissectortable = DissectorTable.get('p4_srcRoutes.bos') 21 | mydissectortable:try(buffer(0,1):bitfield(7,1), buffer:range(3):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_srcRoutes.bos','P4_SRCROUTES.BOS',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('p4_srcRoutes.bos') 32 | my_table:add(0x0,p4_srcroutes) 33 | -------------------------------------------------------------------------------- /samples/hula/output/wireshark/hula_4_udp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_udp = Proto('p4_udp','P4_UDPProtocol') 3 | 4 | -- protocol fields 5 | local p4_udp_srcPort = ProtoField.string('p4_udp.srcPort','srcPort') 6 | local p4_udp_dstPort = ProtoField.string('p4_udp.dstPort','dstPort') 7 | local p4_udp_length_ = ProtoField.string('p4_udp.length_','length_') 8 | local p4_udp_checksum = ProtoField.string('p4_udp.checksum','checksum') 9 | p4_udp.fields = {p4_udp_srcPort, p4_udp_dstPort, p4_udp_length_, p4_udp_checksum} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_udp.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_UDP' 15 | local subtree = tree:add(p4_udp,buffer(),'P4_UDP Protocol Data') 16 | subtree:add(p4_udp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_udp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_udp_length_,tostring(buffer(4,2):bitfield(0,16))) 19 | subtree:add(p4_udp_checksum,tostring(buffer(6,2):bitfield(0,16))) 20 | 21 | end 22 | 23 | print( (require 'debug').getinfo(1).source ) 24 | 25 | -- creation of table for next layer(if required) 26 | 27 | -- No table required 28 | 29 | -- protocol registration 30 | my_table = DissectorTable.get('p4_ipv4.protocol') 31 | my_table:add(0x11,p4_udp) 32 | -------------------------------------------------------------------------------- /samples/hula/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/hula/output/wireshark/hula_1_hula.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/hula/output/wireshark/hula_2_srcRoutes.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/hula/output/wireshark/hula_3_ipv4.lua') 4 | dofile('/home/raj/workspace/p4-traffictool/samples/hula/output/wireshark/hula_4_udp.lua') 5 | -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_accident_alert.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleAccident_alertLayer 2 | 3 | #include "linear_road_accident_alert.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint16_t Accident_alertLayer::getTime(){ 13 | uint16_t time; 14 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 15 | time = htons(hdrdata->time); 16 | return time; 17 | } 18 | 19 | void Accident_alertLayer::setTime(uint16_t value){ 20 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 21 | hdrdata->time = htons(value); 22 | } 23 | uint32_t Accident_alertLayer::getVid(){ 24 | uint32_t vid; 25 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 26 | vid = htonl(hdrdata->vid); 27 | return vid; 28 | } 29 | 30 | void Accident_alertLayer::setVid(uint32_t value){ 31 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 32 | hdrdata->vid = htonl(value); 33 | } 34 | uint16_t Accident_alertLayer::getEmit(){ 35 | uint16_t emit; 36 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 37 | emit = htons(hdrdata->emit); 38 | return emit; 39 | } 40 | 41 | void Accident_alertLayer::setEmit(uint16_t value){ 42 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 43 | hdrdata->emit = htons(value); 44 | } 45 | uint8_t Accident_alertLayer::getSeg(){ 46 | uint8_t seg; 47 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 48 | seg = (hdrdata->seg); 49 | return seg; 50 | } 51 | 52 | void Accident_alertLayer::setSeg(uint8_t value){ 53 | accident_alerthdr* hdrdata = (accident_alerthdr*)m_Data; 54 | hdrdata->seg = (value); 55 | } 56 | void Accident_alertLayer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(accident_alerthdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Accident_alertLayer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_accident_alert.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'accident_alert' 2 | 3 | #ifndef P4_ACCIDENT_ALERT_LAYER 4 | #define P4_ACCIDENT_ALERT_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct accident_alerthdr{ 20 | uint16_t time; 21 | uint32_t vid; 22 | uint16_t emit; 23 | uint8_t seg; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Accident_alertLayer: public Layer{ 28 | public: 29 | Accident_alertLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_ACCIDENT_ALERT;} 30 | Accident_alertLayer(){ 31 | m_DataLen = sizeof(accident_alerthdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_ACCIDENT_ALERT; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint16_t getTime(); 39 | void setTime(uint16_t value); 40 | uint32_t getVid(); 41 | void setVid(uint32_t value); 42 | uint16_t getEmit(); 43 | void setEmit(uint16_t value); 44 | uint8_t getSeg(); 45 | void setSeg(uint8_t value); 46 | 47 | inline accident_alerthdr* getAccident_alertHeader() { return (accident_alerthdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(accident_alerthdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_accnt_bal.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleAccnt_balLayer 2 | 3 | #include "linear_road_accnt_bal.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint16_t Accnt_balLayer::getTime(){ 13 | uint16_t time; 14 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 15 | time = htons(hdrdata->time); 16 | return time; 17 | } 18 | 19 | void Accnt_balLayer::setTime(uint16_t value){ 20 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 21 | hdrdata->time = htons(value); 22 | } 23 | uint32_t Accnt_balLayer::getVid(){ 24 | uint32_t vid; 25 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 26 | vid = htonl(hdrdata->vid); 27 | return vid; 28 | } 29 | 30 | void Accnt_balLayer::setVid(uint32_t value){ 31 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 32 | hdrdata->vid = htonl(value); 33 | } 34 | uint16_t Accnt_balLayer::getEmit(){ 35 | uint16_t emit; 36 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 37 | emit = htons(hdrdata->emit); 38 | return emit; 39 | } 40 | 41 | void Accnt_balLayer::setEmit(uint16_t value){ 42 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 43 | hdrdata->emit = htons(value); 44 | } 45 | uint32_t Accnt_balLayer::getQid(){ 46 | uint32_t qid; 47 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 48 | qid = htonl(hdrdata->qid); 49 | return qid; 50 | } 51 | 52 | void Accnt_balLayer::setQid(uint32_t value){ 53 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 54 | hdrdata->qid = htonl(value); 55 | } 56 | uint32_t Accnt_balLayer::getBal(){ 57 | uint32_t bal; 58 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 59 | bal = htonl(hdrdata->bal); 60 | return bal; 61 | } 62 | 63 | void Accnt_balLayer::setBal(uint32_t value){ 64 | accnt_balhdr* hdrdata = (accnt_balhdr*)m_Data; 65 | hdrdata->bal = htonl(value); 66 | } 67 | void Accnt_balLayer::parseNextLayer(){ 68 | if (m_DataLen <= sizeof(accnt_balhdr)) 69 | return; 70 | 71 | } 72 | 73 | std::string Accnt_balLayer::toString(){ return ""; } 74 | 75 | } -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_accnt_bal.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'accnt_bal' 2 | 3 | #ifndef P4_ACCNT_BAL_LAYER 4 | #define P4_ACCNT_BAL_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct accnt_balhdr{ 20 | uint16_t time; 21 | uint32_t vid; 22 | uint16_t emit; 23 | uint32_t qid; 24 | uint32_t bal; 25 | }; 26 | 27 | #pragma pack(pop) 28 | class Accnt_balLayer: public Layer{ 29 | public: 30 | Accnt_balLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_ACCNT_BAL;} 31 | Accnt_balLayer(){ 32 | m_DataLen = sizeof(accnt_balhdr); 33 | m_Data = new uint8_t[m_DataLen]; 34 | memset(m_Data, 0, m_DataLen); 35 | m_Protocol = P4_ACCNT_BAL; 36 | } 37 | 38 | // Getters and Setters for fields 39 | uint16_t getTime(); 40 | void setTime(uint16_t value); 41 | uint32_t getVid(); 42 | void setVid(uint32_t value); 43 | uint16_t getEmit(); 44 | void setEmit(uint16_t value); 45 | uint32_t getQid(); 46 | void setQid(uint32_t value); 47 | uint32_t getBal(); 48 | void setBal(uint32_t value); 49 | 50 | inline accnt_balhdr* getAccnt_balHeader() { return (accnt_balhdr*)m_Data; } 51 | 52 | void parseNextLayer(); 53 | 54 | inline size_t getHeaderLen() { return sizeof(accnt_balhdr); } 55 | 56 | void computeCalculateFields() {} 57 | 58 | std::string toString(); 59 | 60 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 61 | 62 | }; 63 | } 64 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_accnt_bal_req.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleAccnt_bal_reqLayer 2 | 3 | #include "linear_road_accnt_bal_req.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint16_t Accnt_bal_reqLayer::getTime(){ 13 | uint16_t time; 14 | accnt_bal_reqhdr* hdrdata = (accnt_bal_reqhdr*)m_Data; 15 | time = htons(hdrdata->time); 16 | return time; 17 | } 18 | 19 | void Accnt_bal_reqLayer::setTime(uint16_t value){ 20 | accnt_bal_reqhdr* hdrdata = (accnt_bal_reqhdr*)m_Data; 21 | hdrdata->time = htons(value); 22 | } 23 | uint32_t Accnt_bal_reqLayer::getVid(){ 24 | uint32_t vid; 25 | accnt_bal_reqhdr* hdrdata = (accnt_bal_reqhdr*)m_Data; 26 | vid = htonl(hdrdata->vid); 27 | return vid; 28 | } 29 | 30 | void Accnt_bal_reqLayer::setVid(uint32_t value){ 31 | accnt_bal_reqhdr* hdrdata = (accnt_bal_reqhdr*)m_Data; 32 | hdrdata->vid = htonl(value); 33 | } 34 | uint32_t Accnt_bal_reqLayer::getQid(){ 35 | uint32_t qid; 36 | accnt_bal_reqhdr* hdrdata = (accnt_bal_reqhdr*)m_Data; 37 | qid = htonl(hdrdata->qid); 38 | return qid; 39 | } 40 | 41 | void Accnt_bal_reqLayer::setQid(uint32_t value){ 42 | accnt_bal_reqhdr* hdrdata = (accnt_bal_reqhdr*)m_Data; 43 | hdrdata->qid = htonl(value); 44 | } 45 | void Accnt_bal_reqLayer::parseNextLayer(){ 46 | if (m_DataLen <= sizeof(accnt_bal_reqhdr)) 47 | return; 48 | 49 | } 50 | 51 | std::string Accnt_bal_reqLayer::toString(){ return ""; } 52 | 53 | } -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_accnt_bal_req.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'accnt_bal_req' 2 | 3 | #ifndef P4_ACCNT_BAL_REQ_LAYER 4 | #define P4_ACCNT_BAL_REQ_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct accnt_bal_reqhdr{ 20 | uint16_t time; 21 | uint32_t vid; 22 | uint32_t qid; 23 | }; 24 | 25 | #pragma pack(pop) 26 | class Accnt_bal_reqLayer: public Layer{ 27 | public: 28 | Accnt_bal_reqLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_ACCNT_BAL_REQ;} 29 | Accnt_bal_reqLayer(){ 30 | m_DataLen = sizeof(accnt_bal_reqhdr); 31 | m_Data = new uint8_t[m_DataLen]; 32 | memset(m_Data, 0, m_DataLen); 33 | m_Protocol = P4_ACCNT_BAL_REQ; 34 | } 35 | 36 | // Getters and Setters for fields 37 | uint16_t getTime(); 38 | void setTime(uint16_t value); 39 | uint32_t getVid(); 40 | void setVid(uint32_t value); 41 | uint32_t getQid(); 42 | void setQid(uint32_t value); 43 | 44 | inline accnt_bal_reqhdr* getAccnt_bal_reqHeader() { return (accnt_bal_reqhdr*)m_Data; } 45 | 46 | void parseNextLayer(); 47 | 48 | inline size_t getHeaderLen() { return sizeof(accnt_bal_reqhdr); } 49 | 50 | void computeCalculateFields() {} 51 | 52 | std::string toString(); 53 | 54 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 55 | 56 | }; 57 | } 58 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_expenditure_report.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleExpenditure_reportLayer 2 | 3 | #include "linear_road_expenditure_report.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint16_t Expenditure_reportLayer::getTime(){ 13 | uint16_t time; 14 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 15 | time = htons(hdrdata->time); 16 | return time; 17 | } 18 | 19 | void Expenditure_reportLayer::setTime(uint16_t value){ 20 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 21 | hdrdata->time = htons(value); 22 | } 23 | uint16_t Expenditure_reportLayer::getEmit(){ 24 | uint16_t emit; 25 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 26 | emit = htons(hdrdata->emit); 27 | return emit; 28 | } 29 | 30 | void Expenditure_reportLayer::setEmit(uint16_t value){ 31 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 32 | hdrdata->emit = htons(value); 33 | } 34 | uint32_t Expenditure_reportLayer::getQid(){ 35 | uint32_t qid; 36 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 37 | qid = htonl(hdrdata->qid); 38 | return qid; 39 | } 40 | 41 | void Expenditure_reportLayer::setQid(uint32_t value){ 42 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 43 | hdrdata->qid = htonl(value); 44 | } 45 | uint16_t Expenditure_reportLayer::getBal(){ 46 | uint16_t bal; 47 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 48 | bal = htons(hdrdata->bal); 49 | return bal; 50 | } 51 | 52 | void Expenditure_reportLayer::setBal(uint16_t value){ 53 | expenditure_reporthdr* hdrdata = (expenditure_reporthdr*)m_Data; 54 | hdrdata->bal = htons(value); 55 | } 56 | void Expenditure_reportLayer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(expenditure_reporthdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Expenditure_reportLayer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_expenditure_report.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'expenditure_report' 2 | 3 | #ifndef P4_EXPENDITURE_REPORT_LAYER 4 | #define P4_EXPENDITURE_REPORT_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct expenditure_reporthdr{ 20 | uint16_t time; 21 | uint16_t emit; 22 | uint32_t qid; 23 | uint16_t bal; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Expenditure_reportLayer: public Layer{ 28 | public: 29 | Expenditure_reportLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_EXPENDITURE_REPORT;} 30 | Expenditure_reportLayer(){ 31 | m_DataLen = sizeof(expenditure_reporthdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_EXPENDITURE_REPORT; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint16_t getTime(); 39 | void setTime(uint16_t value); 40 | uint16_t getEmit(); 41 | void setEmit(uint16_t value); 42 | uint32_t getQid(); 43 | void setQid(uint32_t value); 44 | uint16_t getBal(); 45 | void setBal(uint16_t value); 46 | 47 | inline expenditure_reporthdr* getExpenditure_reportHeader() { return (expenditure_reporthdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(expenditure_reporthdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_expenditure_req.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleExpenditure_reqLayer 2 | 3 | #include "linear_road_expenditure_req.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint16_t Expenditure_reqLayer::getTime(){ 13 | uint16_t time; 14 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 15 | time = htons(hdrdata->time); 16 | return time; 17 | } 18 | 19 | void Expenditure_reqLayer::setTime(uint16_t value){ 20 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 21 | hdrdata->time = htons(value); 22 | } 23 | uint32_t Expenditure_reqLayer::getVid(){ 24 | uint32_t vid; 25 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 26 | vid = htonl(hdrdata->vid); 27 | return vid; 28 | } 29 | 30 | void Expenditure_reqLayer::setVid(uint32_t value){ 31 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 32 | hdrdata->vid = htonl(value); 33 | } 34 | uint32_t Expenditure_reqLayer::getQid(){ 35 | uint32_t qid; 36 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 37 | qid = htonl(hdrdata->qid); 38 | return qid; 39 | } 40 | 41 | void Expenditure_reqLayer::setQid(uint32_t value){ 42 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 43 | hdrdata->qid = htonl(value); 44 | } 45 | uint8_t Expenditure_reqLayer::getXway(){ 46 | uint8_t xway; 47 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 48 | xway = (hdrdata->xway); 49 | return xway; 50 | } 51 | 52 | void Expenditure_reqLayer::setXway(uint8_t value){ 53 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 54 | hdrdata->xway = (value); 55 | } 56 | uint8_t Expenditure_reqLayer::getDay(){ 57 | uint8_t day; 58 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 59 | day = (hdrdata->day); 60 | return day; 61 | } 62 | 63 | void Expenditure_reqLayer::setDay(uint8_t value){ 64 | expenditure_reqhdr* hdrdata = (expenditure_reqhdr*)m_Data; 65 | hdrdata->day = (value); 66 | } 67 | void Expenditure_reqLayer::parseNextLayer(){ 68 | if (m_DataLen <= sizeof(expenditure_reqhdr)) 69 | return; 70 | 71 | } 72 | 73 | std::string Expenditure_reqLayer::toString(){ return ""; } 74 | 75 | } -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_expenditure_req.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'expenditure_req' 2 | 3 | #ifndef P4_EXPENDITURE_REQ_LAYER 4 | #define P4_EXPENDITURE_REQ_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct expenditure_reqhdr{ 20 | uint16_t time; 21 | uint32_t vid; 22 | uint32_t qid; 23 | uint8_t xway; 24 | uint8_t day; 25 | }; 26 | 27 | #pragma pack(pop) 28 | class Expenditure_reqLayer: public Layer{ 29 | public: 30 | Expenditure_reqLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_EXPENDITURE_REQ;} 31 | Expenditure_reqLayer(){ 32 | m_DataLen = sizeof(expenditure_reqhdr); 33 | m_Data = new uint8_t[m_DataLen]; 34 | memset(m_Data, 0, m_DataLen); 35 | m_Protocol = P4_EXPENDITURE_REQ; 36 | } 37 | 38 | // Getters and Setters for fields 39 | uint16_t getTime(); 40 | void setTime(uint16_t value); 41 | uint32_t getVid(); 42 | void setVid(uint32_t value); 43 | uint32_t getQid(); 44 | void setQid(uint32_t value); 45 | uint8_t getXway(); 46 | void setXway(uint8_t value); 47 | uint8_t getDay(); 48 | void setDay(uint8_t value); 49 | 50 | inline expenditure_reqhdr* getExpenditure_reqHeader() { return (expenditure_reqhdr*)m_Data; } 51 | 52 | void parseNextLayer(); 53 | 54 | inline size_t getHeaderLen() { return sizeof(expenditure_reqhdr); } 55 | 56 | void computeCalculateFields() {} 57 | 58 | std::string toString(); 59 | 60 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 61 | 62 | }; 63 | } 64 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_lr_msg_type.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleLr_msg_typeLayer 2 | 3 | #include "linear_road_lr_msg_type.h" 4 | #include "linear_road_pos_report.h" 5 | #include "linear_road_accnt_bal_req.h" 6 | #include "linear_road_toll_notification.h" 7 | #include "linear_road_accident_alert.h" 8 | #include "linear_road_accnt_bal.h" 9 | #include "linear_road_expenditure_req.h" 10 | #include "linear_road_expenditure_report.h" 11 | #include "linear_road_travel_estimate_req.h" 12 | #include "linear_road_travel_estimate.h" 13 | #include "PayloadLayer.h" 14 | #include "IpUtils.h" 15 | #include "Logger.h" 16 | #include 17 | #include 18 | #include 19 | 20 | namespace pcpp{ 21 | uint8_t Lr_msg_typeLayer::getMsg_type(){ 22 | uint8_t msg_type; 23 | lr_msg_typehdr* hdrdata = (lr_msg_typehdr*)m_Data; 24 | msg_type = (hdrdata->msg_type); 25 | return msg_type; 26 | } 27 | 28 | void Lr_msg_typeLayer::setMsg_type(uint8_t value){ 29 | lr_msg_typehdr* hdrdata = (lr_msg_typehdr*)m_Data; 30 | hdrdata->msg_type = (value); 31 | } 32 | void Lr_msg_typeLayer::parseNextLayer(){ 33 | if (m_DataLen <= sizeof(lr_msg_typehdr)) 34 | return; 35 | 36 | uint8_t msg_type = Lr_msg_typeLayer::getMsg_type(); 37 | if (msg_type == 0x00) 38 | if (msg_type == 0x02) 39 | if (msg_type == 0x0a) 40 | if (msg_type == 0x0b) 41 | if (msg_type == 0x0c) 42 | if (msg_type == 0x03) 43 | if (msg_type == 0x0d) 44 | if (msg_type == 0x04) 45 | m_NextLayer = new Travel_estimate_reqLayer(m_Data+sizeof(lr_msg_typehdr), m_DataLen - sizeof(lr_msg_typehdr), this, m_Packet); 46 | else if (msg_type == 0x0e) 47 | m_NextLayer = new Travel_estimateLayer(m_Data+sizeof(lr_msg_typehdr), m_DataLen - sizeof(lr_msg_typehdr), this, m_Packet); 48 | else 49 | m_NextLayer = new PayloadLayer(m_Data + sizeof(lr_msg_typehdr), m_DataLen - sizeof(lr_msg_typehdr), this, m_Packet); 50 | } 51 | 52 | std::string Lr_msg_typeLayer::toString(){ return ""; } 53 | 54 | } -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_lr_msg_type.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'lr_msg_type' 2 | 3 | #ifndef P4_LR_MSG_TYPE_LAYER 4 | #define P4_LR_MSG_TYPE_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct lr_msg_typehdr{ 20 | uint8_t msg_type; 21 | }; 22 | 23 | #pragma pack(pop) 24 | class Lr_msg_typeLayer: public Layer{ 25 | public: 26 | Lr_msg_typeLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_LR_MSG_TYPE;} 27 | Lr_msg_typeLayer(){ 28 | m_DataLen = sizeof(lr_msg_typehdr); 29 | m_Data = new uint8_t[m_DataLen]; 30 | memset(m_Data, 0, m_DataLen); 31 | m_Protocol = P4_LR_MSG_TYPE; 32 | } 33 | 34 | // Getters and Setters for fields 35 | uint8_t getMsg_type(); 36 | void setMsg_type(uint8_t value); 37 | 38 | inline lr_msg_typehdr* getLr_msg_typeHeader() { return (lr_msg_typehdr*)m_Data; } 39 | 40 | void parseNextLayer(); 41 | 42 | inline size_t getHeaderLen() { return sizeof(lr_msg_typehdr); } 43 | 44 | void computeCalculateFields() {} 45 | 46 | std::string toString(); 47 | 48 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 49 | 50 | }; 51 | } 52 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_pos_report.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'pos_report' 2 | 3 | #ifndef P4_POS_REPORT_LAYER 4 | #define P4_POS_REPORT_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct pos_reporthdr{ 20 | uint16_t time; 21 | uint32_t vid; 22 | uint8_t spd; 23 | uint8_t xway; 24 | uint8_t lane; 25 | uint8_t dir; 26 | uint8_t seg; 27 | }; 28 | 29 | #pragma pack(pop) 30 | class Pos_reportLayer: public Layer{ 31 | public: 32 | Pos_reportLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_POS_REPORT;} 33 | Pos_reportLayer(){ 34 | m_DataLen = sizeof(pos_reporthdr); 35 | m_Data = new uint8_t[m_DataLen]; 36 | memset(m_Data, 0, m_DataLen); 37 | m_Protocol = P4_POS_REPORT; 38 | } 39 | 40 | // Getters and Setters for fields 41 | uint16_t getTime(); 42 | void setTime(uint16_t value); 43 | uint32_t getVid(); 44 | void setVid(uint32_t value); 45 | uint8_t getSpd(); 46 | void setSpd(uint8_t value); 47 | uint8_t getXway(); 48 | void setXway(uint8_t value); 49 | uint8_t getLane(); 50 | void setLane(uint8_t value); 51 | uint8_t getDir(); 52 | void setDir(uint8_t value); 53 | uint8_t getSeg(); 54 | void setSeg(uint8_t value); 55 | 56 | inline pos_reporthdr* getPos_reportHeader() { return (pos_reporthdr*)m_Data; } 57 | 58 | void parseNextLayer(); 59 | 60 | inline size_t getHeaderLen() { return sizeof(pos_reporthdr); } 61 | 62 | void computeCalculateFields() {} 63 | 64 | std::string toString(); 65 | 66 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 67 | 68 | }; 69 | } 70 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_toll_notification.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'toll_notification' 2 | 3 | #ifndef P4_TOLL_NOTIFICATION_LAYER 4 | #define P4_TOLL_NOTIFICATION_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct toll_notificationhdr{ 20 | uint16_t time; 21 | uint32_t vid; 22 | uint16_t emit; 23 | uint8_t spd; 24 | uint16_t toll; 25 | }; 26 | 27 | #pragma pack(pop) 28 | class Toll_notificationLayer: public Layer{ 29 | public: 30 | Toll_notificationLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_TOLL_NOTIFICATION;} 31 | Toll_notificationLayer(){ 32 | m_DataLen = sizeof(toll_notificationhdr); 33 | m_Data = new uint8_t[m_DataLen]; 34 | memset(m_Data, 0, m_DataLen); 35 | m_Protocol = P4_TOLL_NOTIFICATION; 36 | } 37 | 38 | // Getters and Setters for fields 39 | uint16_t getTime(); 40 | void setTime(uint16_t value); 41 | uint32_t getVid(); 42 | void setVid(uint32_t value); 43 | uint16_t getEmit(); 44 | void setEmit(uint16_t value); 45 | uint8_t getSpd(); 46 | void setSpd(uint8_t value); 47 | uint16_t getToll(); 48 | void setToll(uint16_t value); 49 | 50 | inline toll_notificationhdr* getToll_notificationHeader() { return (toll_notificationhdr*)m_Data; } 51 | 52 | void parseNextLayer(); 53 | 54 | inline size_t getHeaderLen() { return sizeof(toll_notificationhdr); } 55 | 56 | void computeCalculateFields() {} 57 | 58 | std::string toString(); 59 | 60 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 61 | 62 | }; 63 | } 64 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_travel_estimate.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleTravel_estimateLayer 2 | 3 | #include "linear_road_travel_estimate.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Travel_estimateLayer::getQid(){ 13 | uint32_t qid; 14 | travel_estimatehdr* hdrdata = (travel_estimatehdr*)m_Data; 15 | qid = htonl(hdrdata->qid); 16 | return qid; 17 | } 18 | 19 | void Travel_estimateLayer::setQid(uint32_t value){ 20 | travel_estimatehdr* hdrdata = (travel_estimatehdr*)m_Data; 21 | hdrdata->qid = htonl(value); 22 | } 23 | uint16_t Travel_estimateLayer::getTravel_time(){ 24 | uint16_t travel_time; 25 | travel_estimatehdr* hdrdata = (travel_estimatehdr*)m_Data; 26 | travel_time = htons(hdrdata->travel_time); 27 | return travel_time; 28 | } 29 | 30 | void Travel_estimateLayer::setTravel_time(uint16_t value){ 31 | travel_estimatehdr* hdrdata = (travel_estimatehdr*)m_Data; 32 | hdrdata->travel_time = htons(value); 33 | } 34 | uint16_t Travel_estimateLayer::getToll(){ 35 | uint16_t toll; 36 | travel_estimatehdr* hdrdata = (travel_estimatehdr*)m_Data; 37 | toll = htons(hdrdata->toll); 38 | return toll; 39 | } 40 | 41 | void Travel_estimateLayer::setToll(uint16_t value){ 42 | travel_estimatehdr* hdrdata = (travel_estimatehdr*)m_Data; 43 | hdrdata->toll = htons(value); 44 | } 45 | void Travel_estimateLayer::parseNextLayer(){ 46 | if (m_DataLen <= sizeof(travel_estimatehdr)) 47 | return; 48 | 49 | } 50 | 51 | std::string Travel_estimateLayer::toString(){ return ""; } 52 | 53 | } -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_travel_estimate.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'travel_estimate' 2 | 3 | #ifndef P4_TRAVEL_ESTIMATE_LAYER 4 | #define P4_TRAVEL_ESTIMATE_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct travel_estimatehdr{ 20 | uint32_t qid; 21 | uint16_t travel_time; 22 | uint16_t toll; 23 | }; 24 | 25 | #pragma pack(pop) 26 | class Travel_estimateLayer: public Layer{ 27 | public: 28 | Travel_estimateLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_TRAVEL_ESTIMATE;} 29 | Travel_estimateLayer(){ 30 | m_DataLen = sizeof(travel_estimatehdr); 31 | m_Data = new uint8_t[m_DataLen]; 32 | memset(m_Data, 0, m_DataLen); 33 | m_Protocol = P4_TRAVEL_ESTIMATE; 34 | } 35 | 36 | // Getters and Setters for fields 37 | uint32_t getQid(); 38 | void setQid(uint32_t value); 39 | uint16_t getTravel_time(); 40 | void setTravel_time(uint16_t value); 41 | uint16_t getToll(); 42 | void setToll(uint16_t value); 43 | 44 | inline travel_estimatehdr* getTravel_estimateHeader() { return (travel_estimatehdr*)m_Data; } 45 | 46 | void parseNextLayer(); 47 | 48 | inline size_t getHeaderLen() { return sizeof(travel_estimatehdr); } 49 | 50 | void computeCalculateFields() {} 51 | 52 | std::string toString(); 53 | 54 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 55 | 56 | }; 57 | } 58 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/pcapplusplus/linear_road_travel_estimate_req.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'travel_estimate_req' 2 | 3 | #ifndef P4_TRAVEL_ESTIMATE_REQ_LAYER 4 | #define P4_TRAVEL_ESTIMATE_REQ_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct travel_estimate_reqhdr{ 20 | uint16_t time; 21 | uint32_t qid; 22 | uint8_t xway; 23 | uint8_t seg_init; 24 | uint8_t seg_end; 25 | uint8_t dow; 26 | uint8_t tod; 27 | }; 28 | 29 | #pragma pack(pop) 30 | class Travel_estimate_reqLayer: public Layer{ 31 | public: 32 | Travel_estimate_reqLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_TRAVEL_ESTIMATE_REQ;} 33 | Travel_estimate_reqLayer(){ 34 | m_DataLen = sizeof(travel_estimate_reqhdr); 35 | m_Data = new uint8_t[m_DataLen]; 36 | memset(m_Data, 0, m_DataLen); 37 | m_Protocol = P4_TRAVEL_ESTIMATE_REQ; 38 | } 39 | 40 | // Getters and Setters for fields 41 | uint16_t getTime(); 42 | void setTime(uint16_t value); 43 | uint32_t getQid(); 44 | void setQid(uint32_t value); 45 | uint8_t getXway(); 46 | void setXway(uint8_t value); 47 | uint8_t getSeg_init(); 48 | void setSeg_init(uint8_t value); 49 | uint8_t getSeg_end(); 50 | void setSeg_end(uint8_t value); 51 | uint8_t getDow(); 52 | void setDow(uint8_t value); 53 | uint8_t getTod(); 54 | void setTod(uint8_t value); 55 | 56 | inline travel_estimate_reqhdr* getTravel_estimate_reqHeader() { return (travel_estimate_reqhdr*)m_Data; } 57 | 58 | void parseNextLayer(); 59 | 60 | inline size_t getHeaderLen() { return sizeof(travel_estimate_reqhdr); } 61 | 62 | void computeCalculateFields() {} 63 | 64 | std::string toString(); 65 | 66 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 67 | 68 | }; 69 | } 70 | #endif -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_1_ipv4.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_2_udp.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_3_lr_msg_type.lua') 4 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_4_pos_report.lua') 5 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_5_accnt_bal_req.lua') 6 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_6_toll_notification.lua') 7 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_7_accident_alert.lua') 8 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_8_accnt_bal.lua') 9 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_9_expenditure_req.lua') 10 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_10_expenditure_report.lua') 11 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_11_travel_estimate_req.lua') 12 | dofile('/home/raj/workspace/p4-traffictool/samples/linear_road/output/wireshark/linear_road_12_travel_estimate.lua') 13 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_10_expenditure_report.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_expenditure_report = Proto('p4_expenditure_report','P4_EXPENDITURE_REPORTProtocol') 3 | 4 | -- protocol fields 5 | local p4_expenditure_report_time = ProtoField.string('p4_expenditure_report.time','time') 6 | local p4_expenditure_report_emit = ProtoField.string('p4_expenditure_report.emit','emit') 7 | local p4_expenditure_report_qid = ProtoField.string('p4_expenditure_report.qid','qid') 8 | local p4_expenditure_report_bal = ProtoField.string('p4_expenditure_report.bal','bal') 9 | p4_expenditure_report.fields = {p4_expenditure_report_time, p4_expenditure_report_emit, p4_expenditure_report_qid, p4_expenditure_report_bal} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_expenditure_report.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_EXPENDITURE_REPORT' 15 | local subtree = tree:add(p4_expenditure_report,buffer(),'P4_EXPENDITURE_REPORT Protocol Data') 16 | subtree:add(p4_expenditure_report_time,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_expenditure_report_emit,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_expenditure_report_qid,tostring(buffer(4,4):bitfield(0,32))) 19 | subtree:add(p4_expenditure_report_bal,tostring(buffer(8,2):bitfield(0,16))) 20 | 21 | end 22 | 23 | print( (require 'debug').getinfo(1).source ) 24 | 25 | -- creation of table for next layer(if required) 26 | 27 | -- No table required 28 | 29 | -- protocol registration 30 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 31 | my_table:add(0x0d,p4_expenditure_report) 32 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_11_travel_estimate_req.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_travel_estimate_req = Proto('p4_travel_estimate_req','P4_TRAVEL_ESTIMATE_REQProtocol') 3 | 4 | -- protocol fields 5 | local p4_travel_estimate_req_time = ProtoField.string('p4_travel_estimate_req.time','time') 6 | local p4_travel_estimate_req_qid = ProtoField.string('p4_travel_estimate_req.qid','qid') 7 | local p4_travel_estimate_req_xway = ProtoField.string('p4_travel_estimate_req.xway','xway') 8 | local p4_travel_estimate_req_seg_init = ProtoField.string('p4_travel_estimate_req.seg_init','seg_init') 9 | local p4_travel_estimate_req_seg_end = ProtoField.string('p4_travel_estimate_req.seg_end','seg_end') 10 | local p4_travel_estimate_req_dow = ProtoField.string('p4_travel_estimate_req.dow','dow') 11 | local p4_travel_estimate_req_tod = ProtoField.string('p4_travel_estimate_req.tod','tod') 12 | p4_travel_estimate_req.fields = {p4_travel_estimate_req_time, p4_travel_estimate_req_qid, p4_travel_estimate_req_xway, p4_travel_estimate_req_seg_init, p4_travel_estimate_req_seg_end, p4_travel_estimate_req_dow, p4_travel_estimate_req_tod} 13 | 14 | 15 | -- protocol dissector function 16 | function p4_travel_estimate_req.dissector(buffer,pinfo,tree) 17 | pinfo.cols.protocol = 'P4_TRAVEL_ESTIMATE_REQ' 18 | local subtree = tree:add(p4_travel_estimate_req,buffer(),'P4_TRAVEL_ESTIMATE_REQ Protocol Data') 19 | subtree:add(p4_travel_estimate_req_time,tostring(buffer(0,2):bitfield(0,16))) 20 | subtree:add(p4_travel_estimate_req_qid,tostring(buffer(2,4):bitfield(0,32))) 21 | subtree:add(p4_travel_estimate_req_xway,tostring(buffer(6,1):bitfield(0,8))) 22 | subtree:add(p4_travel_estimate_req_seg_init,tostring(buffer(7,1):bitfield(0,8))) 23 | subtree:add(p4_travel_estimate_req_seg_end,tostring(buffer(8,1):bitfield(0,8))) 24 | subtree:add(p4_travel_estimate_req_dow,tostring(buffer(9,1):bitfield(0,8))) 25 | subtree:add(p4_travel_estimate_req_tod,tostring(buffer(10,1):bitfield(0,8))) 26 | 27 | end 28 | 29 | print( (require 'debug').getinfo(1).source ) 30 | 31 | -- creation of table for next layer(if required) 32 | 33 | -- No table required 34 | 35 | -- protocol registration 36 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 37 | my_table:add(0x04,p4_travel_estimate_req) 38 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_12_travel_estimate.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_travel_estimate = Proto('p4_travel_estimate','P4_TRAVEL_ESTIMATEProtocol') 3 | 4 | -- protocol fields 5 | local p4_travel_estimate_qid = ProtoField.string('p4_travel_estimate.qid','qid') 6 | local p4_travel_estimate_travel_time = ProtoField.string('p4_travel_estimate.travel_time','travel_time') 7 | local p4_travel_estimate_toll = ProtoField.string('p4_travel_estimate.toll','toll') 8 | p4_travel_estimate.fields = {p4_travel_estimate_qid, p4_travel_estimate_travel_time, p4_travel_estimate_toll} 9 | 10 | 11 | -- protocol dissector function 12 | function p4_travel_estimate.dissector(buffer,pinfo,tree) 13 | pinfo.cols.protocol = 'P4_TRAVEL_ESTIMATE' 14 | local subtree = tree:add(p4_travel_estimate,buffer(),'P4_TRAVEL_ESTIMATE Protocol Data') 15 | subtree:add(p4_travel_estimate_qid,tostring(buffer(0,4):bitfield(0,32))) 16 | subtree:add(p4_travel_estimate_travel_time,tostring(buffer(4,2):bitfield(0,16))) 17 | subtree:add(p4_travel_estimate_toll,tostring(buffer(6,2):bitfield(0,16))) 18 | 19 | end 20 | 21 | print( (require 'debug').getinfo(1).source ) 22 | 23 | -- creation of table for next layer(if required) 24 | 25 | -- No table required 26 | 27 | -- protocol registration 28 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 29 | my_table:add(0x0e,p4_travel_estimate) 30 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_2_udp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_udp = Proto('p4_udp','P4_UDPProtocol') 3 | 4 | -- protocol fields 5 | local p4_udp_srcPort = ProtoField.string('p4_udp.srcPort','srcPort') 6 | local p4_udp_dstPort = ProtoField.string('p4_udp.dstPort','dstPort') 7 | local p4_udp_length_ = ProtoField.string('p4_udp.length_','length_') 8 | local p4_udp_checksum = ProtoField.string('p4_udp.checksum','checksum') 9 | p4_udp.fields = {p4_udp_srcPort, p4_udp_dstPort, p4_udp_length_, p4_udp_checksum} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_udp.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_UDP' 15 | local subtree = tree:add(p4_udp,buffer(),'P4_UDP Protocol Data') 16 | subtree:add(p4_udp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_udp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_udp_length_,tostring(buffer(4,2):bitfield(0,16))) 19 | subtree:add(p4_udp_checksum,tostring(buffer(6,2):bitfield(0,16))) 20 | local mydissectortable = DissectorTable.get('p4_udp.dstPort') 21 | mydissectortable:try(buffer(2,2):bitfield(0,16), buffer:range(8):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_udp.dstPort','P4_UDP.DSTPORT',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('p4_ipv4.protocol') 32 | my_table:add(0x11,p4_udp) 33 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_3_lr_msg_type.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_lr_msg_type = Proto('p4_lr_msg_type','P4_LR_MSG_TYPEProtocol') 3 | 4 | -- protocol fields 5 | local p4_lr_msg_type_msg_type = ProtoField.string('p4_lr_msg_type.msg_type','msg_type') 6 | p4_lr_msg_type.fields = {p4_lr_msg_type_msg_type} 7 | 8 | 9 | -- protocol dissector function 10 | function p4_lr_msg_type.dissector(buffer,pinfo,tree) 11 | pinfo.cols.protocol = 'P4_LR_MSG_TYPE' 12 | local subtree = tree:add(p4_lr_msg_type,buffer(),'P4_LR_MSG_TYPE Protocol Data') 13 | subtree:add(p4_lr_msg_type_msg_type,tostring(buffer(0,1):bitfield(0,8))) 14 | local mydissectortable = DissectorTable.get('p4_lr_msg_type.msg_type') 15 | mydissectortable:try(buffer(0,1):bitfield(0,8), buffer:range(1):tvb(),pinfo,tree) 16 | 17 | end 18 | 19 | print( (require 'debug').getinfo(1).source ) 20 | 21 | -- creation of table for next layer(if required) 22 | local newdissectortable = DissectorTable.new('p4_lr_msg_type.msg_type','P4_LR_MSG_TYPE.MSG_TYPE',ftypes.STRING) 23 | 24 | -- protocol registration 25 | my_table = DissectorTable.get('p4_udp.dstPort') 26 | my_table:add(0x04d2,p4_lr_msg_type) 27 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_4_pos_report.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_pos_report = Proto('p4_pos_report','P4_POS_REPORTProtocol') 3 | 4 | -- protocol fields 5 | local p4_pos_report_time = ProtoField.string('p4_pos_report.time','time') 6 | local p4_pos_report_vid = ProtoField.string('p4_pos_report.vid','vid') 7 | local p4_pos_report_spd = ProtoField.string('p4_pos_report.spd','spd') 8 | local p4_pos_report_xway = ProtoField.string('p4_pos_report.xway','xway') 9 | local p4_pos_report_lane = ProtoField.string('p4_pos_report.lane','lane') 10 | local p4_pos_report_dir = ProtoField.string('p4_pos_report.dir','dir') 11 | local p4_pos_report_seg = ProtoField.string('p4_pos_report.seg','seg') 12 | p4_pos_report.fields = {p4_pos_report_time, p4_pos_report_vid, p4_pos_report_spd, p4_pos_report_xway, p4_pos_report_lane, p4_pos_report_dir, p4_pos_report_seg} 13 | 14 | 15 | -- protocol dissector function 16 | function p4_pos_report.dissector(buffer,pinfo,tree) 17 | pinfo.cols.protocol = 'P4_POS_REPORT' 18 | local subtree = tree:add(p4_pos_report,buffer(),'P4_POS_REPORT Protocol Data') 19 | subtree:add(p4_pos_report_time,tostring(buffer(0,2):bitfield(0,16))) 20 | subtree:add(p4_pos_report_vid,tostring(buffer(2,4):bitfield(0,32))) 21 | subtree:add(p4_pos_report_spd,tostring(buffer(6,1):bitfield(0,8))) 22 | subtree:add(p4_pos_report_xway,tostring(buffer(7,1):bitfield(0,8))) 23 | subtree:add(p4_pos_report_lane,tostring(buffer(8,1):bitfield(0,8))) 24 | subtree:add(p4_pos_report_dir,tostring(buffer(9,1):bitfield(0,8))) 25 | subtree:add(p4_pos_report_seg,tostring(buffer(10,1):bitfield(0,8))) 26 | 27 | end 28 | 29 | print( (require 'debug').getinfo(1).source ) 30 | 31 | -- creation of table for next layer(if required) 32 | 33 | -- No table required 34 | 35 | -- protocol registration 36 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 37 | my_table:add(0x00,p4_pos_report) 38 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_5_accnt_bal_req.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_accnt_bal_req = Proto('p4_accnt_bal_req','P4_ACCNT_BAL_REQProtocol') 3 | 4 | -- protocol fields 5 | local p4_accnt_bal_req_time = ProtoField.string('p4_accnt_bal_req.time','time') 6 | local p4_accnt_bal_req_vid = ProtoField.string('p4_accnt_bal_req.vid','vid') 7 | local p4_accnt_bal_req_qid = ProtoField.string('p4_accnt_bal_req.qid','qid') 8 | p4_accnt_bal_req.fields = {p4_accnt_bal_req_time, p4_accnt_bal_req_vid, p4_accnt_bal_req_qid} 9 | 10 | 11 | -- protocol dissector function 12 | function p4_accnt_bal_req.dissector(buffer,pinfo,tree) 13 | pinfo.cols.protocol = 'P4_ACCNT_BAL_REQ' 14 | local subtree = tree:add(p4_accnt_bal_req,buffer(),'P4_ACCNT_BAL_REQ Protocol Data') 15 | subtree:add(p4_accnt_bal_req_time,tostring(buffer(0,2):bitfield(0,16))) 16 | subtree:add(p4_accnt_bal_req_vid,tostring(buffer(2,4):bitfield(0,32))) 17 | subtree:add(p4_accnt_bal_req_qid,tostring(buffer(6,4):bitfield(0,32))) 18 | 19 | end 20 | 21 | print( (require 'debug').getinfo(1).source ) 22 | 23 | -- creation of table for next layer(if required) 24 | 25 | -- No table required 26 | 27 | -- protocol registration 28 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 29 | my_table:add(0x02,p4_accnt_bal_req) 30 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_6_toll_notification.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_toll_notification = Proto('p4_toll_notification','P4_TOLL_NOTIFICATIONProtocol') 3 | 4 | -- protocol fields 5 | local p4_toll_notification_time = ProtoField.string('p4_toll_notification.time','time') 6 | local p4_toll_notification_vid = ProtoField.string('p4_toll_notification.vid','vid') 7 | local p4_toll_notification_emit = ProtoField.string('p4_toll_notification.emit','emit') 8 | local p4_toll_notification_spd = ProtoField.string('p4_toll_notification.spd','spd') 9 | local p4_toll_notification_toll = ProtoField.string('p4_toll_notification.toll','toll') 10 | p4_toll_notification.fields = {p4_toll_notification_time, p4_toll_notification_vid, p4_toll_notification_emit, p4_toll_notification_spd, p4_toll_notification_toll} 11 | 12 | 13 | -- protocol dissector function 14 | function p4_toll_notification.dissector(buffer,pinfo,tree) 15 | pinfo.cols.protocol = 'P4_TOLL_NOTIFICATION' 16 | local subtree = tree:add(p4_toll_notification,buffer(),'P4_TOLL_NOTIFICATION Protocol Data') 17 | subtree:add(p4_toll_notification_time,tostring(buffer(0,2):bitfield(0,16))) 18 | subtree:add(p4_toll_notification_vid,tostring(buffer(2,4):bitfield(0,32))) 19 | subtree:add(p4_toll_notification_emit,tostring(buffer(6,2):bitfield(0,16))) 20 | subtree:add(p4_toll_notification_spd,tostring(buffer(8,1):bitfield(0,8))) 21 | subtree:add(p4_toll_notification_toll,tostring(buffer(9,2):bitfield(0,16))) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | 29 | -- No table required 30 | 31 | -- protocol registration 32 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 33 | my_table:add(0x0a,p4_toll_notification) 34 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_7_accident_alert.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_accident_alert = Proto('p4_accident_alert','P4_ACCIDENT_ALERTProtocol') 3 | 4 | -- protocol fields 5 | local p4_accident_alert_time = ProtoField.string('p4_accident_alert.time','time') 6 | local p4_accident_alert_vid = ProtoField.string('p4_accident_alert.vid','vid') 7 | local p4_accident_alert_emit = ProtoField.string('p4_accident_alert.emit','emit') 8 | local p4_accident_alert_seg = ProtoField.string('p4_accident_alert.seg','seg') 9 | p4_accident_alert.fields = {p4_accident_alert_time, p4_accident_alert_vid, p4_accident_alert_emit, p4_accident_alert_seg} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_accident_alert.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_ACCIDENT_ALERT' 15 | local subtree = tree:add(p4_accident_alert,buffer(),'P4_ACCIDENT_ALERT Protocol Data') 16 | subtree:add(p4_accident_alert_time,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_accident_alert_vid,tostring(buffer(2,4):bitfield(0,32))) 18 | subtree:add(p4_accident_alert_emit,tostring(buffer(6,2):bitfield(0,16))) 19 | subtree:add(p4_accident_alert_seg,tostring(buffer(8,1):bitfield(0,8))) 20 | 21 | end 22 | 23 | print( (require 'debug').getinfo(1).source ) 24 | 25 | -- creation of table for next layer(if required) 26 | 27 | -- No table required 28 | 29 | -- protocol registration 30 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 31 | my_table:add(0x0b,p4_accident_alert) 32 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_8_accnt_bal.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_accnt_bal = Proto('p4_accnt_bal','P4_ACCNT_BALProtocol') 3 | 4 | -- protocol fields 5 | local p4_accnt_bal_time = ProtoField.string('p4_accnt_bal.time','time') 6 | local p4_accnt_bal_vid = ProtoField.string('p4_accnt_bal.vid','vid') 7 | local p4_accnt_bal_emit = ProtoField.string('p4_accnt_bal.emit','emit') 8 | local p4_accnt_bal_qid = ProtoField.string('p4_accnt_bal.qid','qid') 9 | local p4_accnt_bal_bal = ProtoField.string('p4_accnt_bal.bal','bal') 10 | p4_accnt_bal.fields = {p4_accnt_bal_time, p4_accnt_bal_vid, p4_accnt_bal_emit, p4_accnt_bal_qid, p4_accnt_bal_bal} 11 | 12 | 13 | -- protocol dissector function 14 | function p4_accnt_bal.dissector(buffer,pinfo,tree) 15 | pinfo.cols.protocol = 'P4_ACCNT_BAL' 16 | local subtree = tree:add(p4_accnt_bal,buffer(),'P4_ACCNT_BAL Protocol Data') 17 | subtree:add(p4_accnt_bal_time,tostring(buffer(0,2):bitfield(0,16))) 18 | subtree:add(p4_accnt_bal_vid,tostring(buffer(2,4):bitfield(0,32))) 19 | subtree:add(p4_accnt_bal_emit,tostring(buffer(6,2):bitfield(0,16))) 20 | subtree:add(p4_accnt_bal_qid,tostring(buffer(8,4):bitfield(0,32))) 21 | subtree:add(p4_accnt_bal_bal,tostring(buffer(12,4):bitfield(0,32))) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | 29 | -- No table required 30 | 31 | -- protocol registration 32 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 33 | my_table:add(0x0c,p4_accnt_bal) 34 | -------------------------------------------------------------------------------- /samples/linear_road/output/wireshark/linear_road_9_expenditure_req.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_expenditure_req = Proto('p4_expenditure_req','P4_EXPENDITURE_REQProtocol') 3 | 4 | -- protocol fields 5 | local p4_expenditure_req_time = ProtoField.string('p4_expenditure_req.time','time') 6 | local p4_expenditure_req_vid = ProtoField.string('p4_expenditure_req.vid','vid') 7 | local p4_expenditure_req_qid = ProtoField.string('p4_expenditure_req.qid','qid') 8 | local p4_expenditure_req_xway = ProtoField.string('p4_expenditure_req.xway','xway') 9 | local p4_expenditure_req_day = ProtoField.string('p4_expenditure_req.day','day') 10 | p4_expenditure_req.fields = {p4_expenditure_req_time, p4_expenditure_req_vid, p4_expenditure_req_qid, p4_expenditure_req_xway, p4_expenditure_req_day} 11 | 12 | 13 | -- protocol dissector function 14 | function p4_expenditure_req.dissector(buffer,pinfo,tree) 15 | pinfo.cols.protocol = 'P4_EXPENDITURE_REQ' 16 | local subtree = tree:add(p4_expenditure_req,buffer(),'P4_EXPENDITURE_REQ Protocol Data') 17 | subtree:add(p4_expenditure_req_time,tostring(buffer(0,2):bitfield(0,16))) 18 | subtree:add(p4_expenditure_req_vid,tostring(buffer(2,4):bitfield(0,32))) 19 | subtree:add(p4_expenditure_req_qid,tostring(buffer(6,4):bitfield(0,32))) 20 | subtree:add(p4_expenditure_req_xway,tostring(buffer(10,1):bitfield(0,8))) 21 | subtree:add(p4_expenditure_req_day,tostring(buffer(11,1):bitfield(0,8))) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | 29 | -- No table required 30 | 31 | -- protocol registration 32 | my_table = DissectorTable.get('p4_lr_msg_type.msg_type') 33 | my_table:add(0x03,p4_expenditure_req) 34 | -------------------------------------------------------------------------------- /samples/mri/output/pcapplusplus/mri_ipv4_option.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'ipv4_option' 2 | 3 | #ifndef P4_IPV4_OPTION_LAYER 4 | #define P4_IPV4_OPTION_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct ipv4_optionhdr{ 20 | uint8_t copyFlag; 21 | uint8_t optClass; 22 | uint8_t option; 23 | uint8_t optionLength; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Ipv4_optionLayer: public Layer{ 28 | public: 29 | Ipv4_optionLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_IPV4_OPTION;} 30 | Ipv4_optionLayer(){ 31 | m_DataLen = sizeof(ipv4_optionhdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_IPV4_OPTION; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint8_t getCopyflag(); 39 | void setCopyflag(uint8_t value); 40 | uint8_t getOptclass(); 41 | void setOptclass(uint8_t value); 42 | uint8_t getOption(); 43 | void setOption(uint8_t value); 44 | uint8_t getOptionlength(); 45 | void setOptionlength(uint8_t value); 46 | 47 | inline ipv4_optionhdr* getIpv4_optionHeader() { return (ipv4_optionhdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(ipv4_optionhdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/mri/output/pcapplusplus/mri_mri.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleMriLayer 2 | 3 | #include "mri_mri.h" 4 | #include "mri_swids.h" 5 | #include "PayloadLayer.h" 6 | #include "IpUtils.h" 7 | #include "Logger.h" 8 | #include 9 | #include 10 | #include 11 | 12 | namespace pcpp{ 13 | uint16_t MriLayer::getCount(){ 14 | uint16_t count; 15 | mrihdr* hdrdata = (mrihdr*)m_Data; 16 | count = htons(hdrdata->count); 17 | return count; 18 | } 19 | 20 | void MriLayer::setCount(uint16_t value){ 21 | mrihdr* hdrdata = (mrihdr*)m_Data; 22 | hdrdata->count = htons(value); 23 | } 24 | void MriLayer::parseNextLayer(){ 25 | if (m_DataLen <= sizeof(mrihdr)) 26 | return; 27 | 28 | uint16_t count = MriLayer::getCount(); 29 | m_NextLayer = new SwidsLayer(m_Data+sizeof(mrihdr), m_DataLen - sizeof(mrihdr), this, m_Packet); 30 | else if (count == 0xfaul) 31 | m_NextLayer = new SwidsLayer(m_Data+sizeof(mrihdr), m_DataLen - sizeof(mrihdr), this, m_Packet); 32 | else 33 | m_NextLayer = new PayloadLayer(m_Data + sizeof(mrihdr), m_DataLen - sizeof(mrihdr), this, m_Packet); 34 | } 35 | 36 | std::string MriLayer::toString(){ return ""; } 37 | 38 | } -------------------------------------------------------------------------------- /samples/mri/output/pcapplusplus/mri_mri.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'mri' 2 | 3 | #ifndef P4_MRI_LAYER 4 | #define P4_MRI_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct mrihdr{ 20 | uint16_t count; 21 | }; 22 | 23 | #pragma pack(pop) 24 | class MriLayer: public Layer{ 25 | public: 26 | MriLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_MRI;} 27 | MriLayer(){ 28 | m_DataLen = sizeof(mrihdr); 29 | m_Data = new uint8_t[m_DataLen]; 30 | memset(m_Data, 0, m_DataLen); 31 | m_Protocol = P4_MRI; 32 | } 33 | 34 | // Getters and Setters for fields 35 | uint16_t getCount(); 36 | void setCount(uint16_t value); 37 | 38 | inline mrihdr* getMriHeader() { return (mrihdr*)m_Data; } 39 | 40 | void parseNextLayer(); 41 | 42 | inline size_t getHeaderLen() { return sizeof(mrihdr); } 43 | 44 | void computeCalculateFields() {} 45 | 46 | std::string toString(); 47 | 48 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 49 | 50 | }; 51 | } 52 | #endif -------------------------------------------------------------------------------- /samples/mri/output/pcapplusplus/mri_swids.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleSwidsLayer 2 | 3 | #include "mri_swids.h" 4 | #include "mri_swids.h" 5 | #include "PayloadLayer.h" 6 | #include "IpUtils.h" 7 | #include "Logger.h" 8 | #include 9 | #include 10 | #include 11 | 12 | namespace pcpp{ 13 | uint32_t SwidsLayer::getSwid(){ 14 | uint32_t swid; 15 | swidshdr* hdrdata = (swidshdr*)m_Data; 16 | swid = htonl(hdrdata->swid); 17 | return swid; 18 | } 19 | 20 | void SwidsLayer::setSwid(uint32_t value){ 21 | swidshdr* hdrdata = (swidshdr*)m_Data; 22 | hdrdata->swid = htonl(value); 23 | } 24 | void SwidsLayer::parseNextLayer(){ 25 | if (m_DataLen <= sizeof(swidshdr)) 26 | return; 27 | 28 | m_NextLayer = new SwidsLayer(m_Data+sizeof(swidshdr), m_DataLen - sizeof(swidshdr), this, m_Packet); 29 | else -------------------------------------------------------------------------------- /samples/mri/output/pcapplusplus/mri_swids.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'swids' 2 | 3 | #ifndef P4_SWIDS_LAYER 4 | #define P4_SWIDS_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct swidshdr{ 20 | uint32_t swid; 21 | }; 22 | 23 | #pragma pack(pop) 24 | class SwidsLayer: public Layer{ 25 | public: 26 | SwidsLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_SWIDS;} 27 | SwidsLayer(){ 28 | m_DataLen = sizeof(swidshdr); 29 | m_Data = new uint8_t[m_DataLen]; 30 | memset(m_Data, 0, m_DataLen); 31 | m_Protocol = P4_SWIDS; 32 | } 33 | 34 | // Getters and Setters for fields 35 | uint32_t getSwid(); 36 | void setSwid(uint32_t value); 37 | 38 | inline swidshdr* getSwidsHeader() { return (swidshdr*)m_Data; } 39 | 40 | void parseNextLayer(); 41 | 42 | inline size_t getHeaderLen() { return sizeof(swidshdr); } 43 | 44 | void computeCalculateFields() {} 45 | 46 | std::string toString(); 47 | 48 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 49 | 50 | }; 51 | } 52 | #endif -------------------------------------------------------------------------------- /samples/mri/output/scapy/mri.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class Ipv4_option(Packet): 5 | name = 'ipv4_option' 6 | fields_desc = [ 7 | XBitField('_pad0', 0, 7), 8 | XBitField('copyFlag', 0, 1), 9 | XBitField('_pad1', 0, 6), 10 | XBitField('optClass', 0, 2), 11 | XBitField('_pad2', 0, 3), 12 | XBitField('option', 0, 5), 13 | XByteField('optionLength', 0), 14 | ] 15 | 16 | def guess_payload_class(self, payload): 17 | if (self.option == 0x1f): 18 | return Mri 19 | else: 20 | return Packet.guess_payload_class(self, payload) 21 | 22 | class Mri(Packet): 23 | name = 'mri' 24 | fields_desc = [ 25 | XShortField('count', 0), 26 | ] 27 | 28 | def guess_payload_class(self, payload): 29 | if (self.count == 0xfaul): 30 | return Swids 31 | else: 32 | return Packet.guess_payload_class(self, payload) 33 | 34 | #update hdrChecksum over [['ipv4', 'version'], ['ipv4', 'ihl'], ['ipv4', 'diffserv'], ['ipv4', 'totalLen'], ['ipv4', 'identification'], ['ipv4', 'flags'], ['ipv4', 'fragOffset'], ['ipv4', 'ttl'], ['ipv4', 'protocol'], ['ipv4', 'srcAddr'], ['ipv4', 'dstAddr']] using csum16 in post_build method 35 | 36 | class Swids(Packet): 37 | name = 'swids' 38 | fields_desc = [ 39 | XIntField('swid', 0), 40 | ] 41 | 42 | def guess_payload_class(self, payload): 43 | -------------------------------------------------------------------------------- /samples/mri/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/mri/output/wireshark/mri_1_ipv4.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/mri/output/wireshark/mri_2_ipv4_option.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/mri/output/wireshark/mri_3_mri.lua') 4 | dofile('/home/raj/workspace/p4-traffictool/samples/mri/output/wireshark/mri_4_swids.lua') 5 | -------------------------------------------------------------------------------- /samples/mri/output/wireshark/mri_2_ipv4_option.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_ipv4_option = Proto('p4_ipv4_option','P4_IPV4_OPTIONProtocol') 3 | 4 | -- protocol fields 5 | local p4_ipv4_option__pad0 = ProtoField.string('p4_ipv4_option._pad0','_pad0') 6 | local p4_ipv4_option_copyFlag = ProtoField.string('p4_ipv4_option.copyFlag','copyFlag') 7 | local p4_ipv4_option__pad1 = ProtoField.string('p4_ipv4_option._pad1','_pad1') 8 | local p4_ipv4_option_optClass = ProtoField.string('p4_ipv4_option.optClass','optClass') 9 | local p4_ipv4_option__pad2 = ProtoField.string('p4_ipv4_option._pad2','_pad2') 10 | local p4_ipv4_option_option = ProtoField.string('p4_ipv4_option.option','option') 11 | local p4_ipv4_option_optionLength = ProtoField.string('p4_ipv4_option.optionLength','optionLength') 12 | p4_ipv4_option.fields = {p4_ipv4_option__pad0, p4_ipv4_option_copyFlag, p4_ipv4_option__pad1, p4_ipv4_option_optClass, p4_ipv4_option__pad2, p4_ipv4_option_option, p4_ipv4_option_optionLength} 13 | 14 | 15 | -- protocol dissector function 16 | function p4_ipv4_option.dissector(buffer,pinfo,tree) 17 | pinfo.cols.protocol = 'P4_IPV4_OPTION' 18 | local subtree = tree:add(p4_ipv4_option,buffer(),'P4_IPV4_OPTION Protocol Data') 19 | subtree:add(p4_ipv4_option__pad0,tostring(buffer(0,1):bitfield(0,7))) 20 | subtree:add(p4_ipv4_option_copyFlag,tostring(buffer(0,1):bitfield(7,1))) 21 | subtree:add(p4_ipv4_option__pad1,tostring(buffer(1,1):bitfield(0,6))) 22 | subtree:add(p4_ipv4_option_optClass,tostring(buffer(1,1):bitfield(6,2))) 23 | subtree:add(p4_ipv4_option__pad2,tostring(buffer(2,1):bitfield(0,3))) 24 | subtree:add(p4_ipv4_option_option,tostring(buffer(2,1):bitfield(3,5))) 25 | subtree:add(p4_ipv4_option_optionLength,tostring(buffer(3,1):bitfield(0,8))) 26 | local mydissectortable = DissectorTable.get('p4_ipv4_option.option') 27 | mydissectortable:try(buffer(2,1):bitfield(3,5), buffer:range(4):tvb(),pinfo,tree) 28 | 29 | end 30 | 31 | print( (require 'debug').getinfo(1).source ) 32 | 33 | -- creation of table for next layer(if required) 34 | local newdissectortable = DissectorTable.new('p4_ipv4_option.option','P4_IPV4_OPTION.OPTION',ftypes.STRING) 35 | 36 | -- protocol registration 37 | my_table = DissectorTable.get('p4_ipv4.ihl') 38 | my_table:add(0x0,p4_ipv4_option) 39 | -------------------------------------------------------------------------------- /samples/mri/output/wireshark/mri_3_mri.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_mri = Proto('p4_mri','P4_MRIProtocol') 3 | 4 | -- protocol fields 5 | local p4_mri_count = ProtoField.string('p4_mri.count','count') 6 | p4_mri.fields = {p4_mri_count} 7 | 8 | 9 | -- protocol dissector function 10 | function p4_mri.dissector(buffer,pinfo,tree) 11 | pinfo.cols.protocol = 'P4_MRI' 12 | local subtree = tree:add(p4_mri,buffer(),'P4_MRI Protocol Data') 13 | subtree:add(p4_mri_count,tostring(buffer(0,2):bitfield(0,16))) 14 | local mydissectortable = DissectorTable.get('p4_mri.count') 15 | mydissectortable:try(buffer(0,2):bitfield(0,16), buffer:range(2):tvb(),pinfo,tree) 16 | 17 | end 18 | 19 | print( (require 'debug').getinfo(1).source ) 20 | 21 | -- creation of table for next layer(if required) 22 | local newdissectortable = DissectorTable.new('p4_mri.count','P4_MRI.COUNT',ftypes.STRING) 23 | 24 | -- protocol registration 25 | my_table = DissectorTable.get('p4_ipv4_option.option') 26 | my_table:add(0x1f,p4_mri) 27 | -------------------------------------------------------------------------------- /samples/mri/output/wireshark/mri_4_swids.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_swids = Proto('p4_swids','P4_SWIDSProtocol') 3 | 4 | -- protocol fields 5 | local p4_swids_swid = ProtoField.string('p4_swids.swid','swid') 6 | p4_swids.fields = {p4_swids_swid} 7 | 8 | 9 | -- protocol dissector function 10 | function p4_swids.dissector(buffer,pinfo,tree) 11 | pinfo.cols.protocol = 'P4_SWIDS' 12 | local subtree = tree:add(p4_swids,buffer(),'P4_SWIDS Protocol Data') 13 | subtree:add(p4_swids_swid,tostring(buffer(0,4):bitfield(0,32))) 14 | local mydissectortable = DissectorTable.get('p4_swids.metadata._parser_metadata_remaining1') 15 | Could not detect suitable parameters 16 | 17 | end 18 | 19 | print( (require 'debug').getinfo(1).source ) 20 | 21 | -- creation of table for next layer(if required) 22 | local newdissectortable = DissectorTable.new('p4_swids.metadata._parser_metadata_remaining1','P4_SWIDS.METADATA._PARSER_METADATA_REMAINING1',ftypes.STRING) 23 | 24 | -- protocol registration 25 | my_table = DissectorTable.get('p4_mri.count') 26 | my_table:add(0x0,p4_swids) 27 | my_table = DissectorTable.get('p4_swids.metadata._parser_metadata_remaining1') 28 | my_table:add(0x0,p4_swids) 29 | -------------------------------------------------------------------------------- /samples/netcache/.Rhistory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NUS-SNL/p4-traffictool/8070dcfc1e91d6102762eab0f0c478e4398ed87b/samples/netcache/.Rhistory -------------------------------------------------------------------------------- /samples/netcache/cache.p4: -------------------------------------------------------------------------------- 1 | header_type nc_cache_md_t { 2 | fields { 3 | cache_exist: 1; 4 | cache_index: 14; 5 | cache_valid: 1; 6 | } 7 | } 8 | metadata nc_cache_md_t nc_cache_md; 9 | 10 | 11 | action check_cache_exist_act(index) { 12 | modify_field (nc_cache_md.cache_exist, 1); 13 | modify_field (nc_cache_md.cache_index, index); 14 | } 15 | table check_cache_exist { 16 | reads { 17 | nc_hdr.key: exact; 18 | } 19 | actions { 20 | check_cache_exist_act; 21 | } 22 | size: NUM_CACHE; 23 | } 24 | 25 | 26 | register cache_valid_reg { 27 | width: 1; 28 | instance_count: NUM_CACHE; 29 | } 30 | 31 | action check_cache_valid_act() { 32 | register_read(nc_cache_md.cache_valid, cache_valid_reg, nc_cache_md.cache_index); 33 | } 34 | table check_cache_valid { 35 | actions { 36 | check_cache_valid_act; 37 | } 38 | //default_action: check_cache_valid_act; 39 | } 40 | 41 | action set_cache_valid_act() { 42 | register_write(cache_valid_reg, nc_cache_md.cache_index, 1); 43 | } 44 | table set_cache_valid { 45 | actions { 46 | set_cache_valid_act; 47 | } 48 | //default_action: set_cache_valid_act; 49 | } 50 | 51 | control process_cache { 52 | apply (check_cache_exist); 53 | if (nc_cache_md.cache_exist == 1) { 54 | if (nc_hdr.op == NC_READ_REQUEST) { 55 | apply (check_cache_valid); 56 | } 57 | else if (nc_hdr.op == NC_UPDATE_REPLY) { 58 | apply (set_cache_valid); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /samples/netcache/ethernet.p4: -------------------------------------------------------------------------------- 1 | action ethernet_set_mac_act (smac, dmac) { 2 | modify_field (ethernet.srcAddr, smac); 3 | modify_field (ethernet.dstAddr, dmac); 4 | } 5 | table ethernet_set_mac { 6 | reads { 7 | standard_metadata.egress_port: exact; 8 | } 9 | actions { 10 | ethernet_set_mac_act; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/netcache/includes/checksum.p4: -------------------------------------------------------------------------------- 1 | field_list ipv4_field_list { 2 | ipv4.version; 3 | ipv4.ihl; 4 | ipv4.diffserv; 5 | ipv4.totalLen; 6 | ipv4.identification; 7 | ipv4.flags; 8 | ipv4.fragOffset; 9 | ipv4.ttl; 10 | ipv4.protocol; 11 | ipv4.srcAddr; 12 | ipv4.dstAddr; 13 | } 14 | field_list_calculation ipv4_chksum_calc { 15 | input { 16 | ipv4_field_list; 17 | } 18 | algorithm : csum16; 19 | output_width: 16; 20 | } 21 | calculated_field ipv4.hdrChecksum { 22 | update ipv4_chksum_calc; 23 | } 24 | 25 | field_list udp_checksum_list { 26 | // IPv4 Pseudo Header Format. Must modify for IPv6 support. 27 | ipv4.srcAddr; 28 | ipv4.dstAddr; 29 | 8'0; 30 | ipv4.protocol; 31 | udp.len; 32 | udp.srcPort; 33 | udp.dstPort; 34 | udp.len; 35 | // udp.checksum; 36 | payload; 37 | } 38 | field_list_calculation udp_checksum { 39 | input { 40 | udp_checksum_list; 41 | } 42 | algorithm : csum16; 43 | output_width : 16; 44 | } 45 | calculated_field udp.checksum { 46 | update udp_checksum; 47 | } 48 | -------------------------------------------------------------------------------- /samples/netcache/includes/defines.p4: -------------------------------------------------------------------------------- 1 | #define NC_PORT 8888 2 | 3 | #define NUM_CACHE 128 4 | 5 | #define NC_READ_REQUEST 0 6 | #define NC_READ_REPLY 1 7 | #define NC_HOT_READ_REQUEST 2 8 | #define NC_WRITE_REQUEST 4 9 | #define NC_WRITE_REPLY 5 10 | #define NC_UPDATE_REQUEST 8 11 | #define NC_UPDATE_REPLY 9 12 | -------------------------------------------------------------------------------- /samples/netcache/includes/headers.p4: -------------------------------------------------------------------------------- 1 | header_type ethernet_t { 2 | fields { 3 | dstAddr : 48; 4 | srcAddr : 48; 5 | etherType : 16; 6 | } 7 | } 8 | header ethernet_t ethernet; 9 | 10 | header_type ipv4_t { 11 | fields { 12 | version : 4; 13 | ihl : 4; 14 | diffserv : 8; 15 | totalLen : 16; 16 | identification : 16; 17 | flags : 3; 18 | fragOffset : 13; 19 | ttl : 8; 20 | protocol : 8; 21 | hdrChecksum : 16; 22 | srcAddr : 32; 23 | dstAddr: 32; 24 | } 25 | } 26 | header ipv4_t ipv4; 27 | 28 | header_type tcp_t { 29 | fields { 30 | srcPort : 16; 31 | dstPort : 16; 32 | seqNo : 32; 33 | ackNo : 32; 34 | dataOffset : 4; 35 | res : 3; 36 | ecn : 3; 37 | ctrl : 6; 38 | window : 16; 39 | checksum : 16; 40 | urgentPtr : 16; 41 | } 42 | } 43 | header tcp_t tcp; 44 | 45 | header_type udp_t { 46 | fields { 47 | srcPort : 16; 48 | dstPort : 16; 49 | len : 16; 50 | checksum : 16; 51 | } 52 | } 53 | header udp_t udp; 54 | 55 | header_type nc_hdr_t { 56 | fields { 57 | op: 8; 58 | key: 64; 59 | } 60 | } 61 | header nc_hdr_t nc_hdr; 62 | 63 | header_type nc_load_t { 64 | fields { 65 | load_1: 32; 66 | load_2: 32; 67 | load_3: 32; 68 | load_4: 32; 69 | } 70 | } 71 | header nc_load_t nc_load; 72 | 73 | /* 74 | The headers for value are defined in value.p4 75 | k = 1, 2, ..., 8 76 | header_type nc_value_{k}_t { 77 | fields { 78 | value_{k}_1: 32; 79 | value_{k}_2: 32; 80 | value_{k}_3: 32; 81 | value_{k}_4: 32; 82 | } 83 | } 84 | */ 85 | -------------------------------------------------------------------------------- /samples/netcache/includes/parsers.p4: -------------------------------------------------------------------------------- 1 | parser start { 2 | return parse_ethernet; 3 | } 4 | 5 | #define ETHER_TYPE_IPV4 0x0800 6 | parser parse_ethernet { 7 | extract (ethernet); 8 | return select (latest.etherType) { 9 | ETHER_TYPE_IPV4: parse_ipv4; 10 | default: ingress; 11 | } 12 | } 13 | 14 | #define IPV4_PROTOCOL_TCP 6 15 | #define IPV4_PROTOCOL_UDP 17 16 | parser parse_ipv4 { 17 | extract(ipv4); 18 | return select (latest.protocol) { 19 | IPV4_PROTOCOL_TCP: parse_tcp; 20 | IPV4_PROTOCOL_UDP: parse_udp; 21 | default: ingress; 22 | } 23 | } 24 | 25 | parser parse_tcp { 26 | extract (tcp); 27 | return ingress; 28 | } 29 | 30 | parser parse_udp { 31 | extract (udp); 32 | return select (latest.dstPort) { 33 | NC_PORT: parse_nc_hdr; 34 | default: ingress; 35 | } 36 | } 37 | 38 | parser parse_nc_hdr { 39 | extract (nc_hdr); 40 | return select(latest.op) { 41 | NC_READ_REQUEST: ingress; 42 | NC_READ_REPLY: parse_value; 43 | NC_HOT_READ_REQUEST: parse_nc_load; 44 | NC_UPDATE_REQUEST: ingress; 45 | NC_UPDATE_REPLY: parse_value; 46 | default: ingress; 47 | } 48 | } 49 | 50 | parser parse_nc_load { 51 | extract (nc_load); 52 | return ingress; 53 | } 54 | 55 | parser parse_value { 56 | return parse_nc_value_1; 57 | } 58 | 59 | /* 60 | The parsers for value headers are defined in value.p4 61 | k = 1, 2, ..., 8 62 | parser parse_value_{k} { 63 | extract (nc_value_{k}); 64 | return select(k) { 65 | 8: ingress; 66 | default: parse_value_{k + 1}; 67 | } 68 | } 69 | */ 70 | -------------------------------------------------------------------------------- /samples/netcache/ipv4.p4: -------------------------------------------------------------------------------- 1 | action set_egress(egress_spec) { 2 | modify_field(standard_metadata.egress_spec, egress_spec); 3 | add_to_field(ipv4.ttl, -1); 4 | } 5 | 6 | @pragma stage 11 7 | table ipv4_route { 8 | reads { 9 | ipv4.dstAddr : exact; 10 | } 11 | actions { 12 | set_egress; 13 | } 14 | size : 8192; 15 | } 16 | -------------------------------------------------------------------------------- /samples/netcache/netcache.p4: -------------------------------------------------------------------------------- 1 | #include "includes/defines.p4" 2 | #include "includes/headers.p4" 3 | #include "includes/parsers.p4" 4 | #include "includes/checksum.p4" 5 | 6 | #include "cache.p4" 7 | #include "heavy_hitter.p4" 8 | #include "value.p4" 9 | #include "ipv4.p4" 10 | #include "ethernet.p4" 11 | 12 | control ingress { 13 | process_cache(); 14 | process_value(); 15 | 16 | apply (ipv4_route); 17 | } 18 | 19 | control egress { 20 | if (nc_hdr.op == NC_READ_REQUEST and nc_cache_md.cache_exist != 1) { 21 | heavy_hitter(); 22 | } 23 | apply (ethernet_set_mac); 24 | } 25 | -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_hdr.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_hdrLayer 2 | 3 | #include "netcache_nc_hdr.h" 4 | #include "netcache_parse_value.h" 5 | #include "netcache_nc_load.h" 6 | #include "netcache_parse_value.h" 7 | #include "PayloadLayer.h" 8 | #include "IpUtils.h" 9 | #include "Logger.h" 10 | #include 11 | #include 12 | #include 13 | 14 | namespace pcpp{ 15 | uint8_t Nc_hdrLayer::getOp(){ 16 | uint8_t op; 17 | nc_hdrhdr* hdrdata = (nc_hdrhdr*)m_Data; 18 | op = (hdrdata->op); 19 | return op; 20 | } 21 | 22 | void Nc_hdrLayer::setOp(uint8_t value){ 23 | nc_hdrhdr* hdrdata = (nc_hdrhdr*)m_Data; 24 | hdrdata->op = (value); 25 | } 26 | uint64_t Nc_hdrLayer::getKey(){ 27 | uint64_t key; 28 | nc_hdrhdr* hdrdata = (nc_hdrhdr*)m_Data; 29 | key = htobe64(hdrdata->key); 30 | return key; 31 | } 32 | 33 | void Nc_hdrLayer::setKey(uint64_t value){ 34 | nc_hdrhdr* hdrdata = (nc_hdrhdr*)m_Data; 35 | hdrdata->key = htobe64(value); 36 | } 37 | void Nc_hdrLayer::parseNextLayer(){ 38 | if (m_DataLen <= sizeof(nc_hdrhdr)) 39 | return; 40 | 41 | uint8_t op = Nc_hdrLayer::getOp(); 42 | if (op == 0x01) 43 | if (op == 0x02) 44 | m_NextLayer = new Nc_loadLayer(m_Data+sizeof(nc_hdrhdr), m_DataLen - sizeof(nc_hdrhdr), this, m_Packet); 45 | else if (op == 0x09) 46 | m_NextLayer = new Parse_valueLayer(m_Data+sizeof(nc_hdrhdr), m_DataLen - sizeof(nc_hdrhdr), this, m_Packet); 47 | else 48 | m_NextLayer = new PayloadLayer(m_Data + sizeof(nc_hdrhdr), m_DataLen - sizeof(nc_hdrhdr), this, m_Packet); 49 | } 50 | 51 | std::string Nc_hdrLayer::toString(){ return ""; } 52 | 53 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_hdr.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_hdr' 2 | 3 | #ifndef P4_NC_HDR_LAYER 4 | #define P4_NC_HDR_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_hdrhdr{ 20 | uint8_t op; 21 | uint64_t key; 22 | }; 23 | 24 | #pragma pack(pop) 25 | class Nc_hdrLayer: public Layer{ 26 | public: 27 | Nc_hdrLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_HDR;} 28 | Nc_hdrLayer(){ 29 | m_DataLen = sizeof(nc_hdrhdr); 30 | m_Data = new uint8_t[m_DataLen]; 31 | memset(m_Data, 0, m_DataLen); 32 | m_Protocol = P4_NC_HDR; 33 | } 34 | 35 | // Getters and Setters for fields 36 | uint8_t getOp(); 37 | void setOp(uint8_t value); 38 | uint64_t getKey(); 39 | void setKey(uint64_t value); 40 | 41 | inline nc_hdrhdr* getNc_hdrHeader() { return (nc_hdrhdr*)m_Data; } 42 | 43 | void parseNextLayer(); 44 | 45 | inline size_t getHeaderLen() { return sizeof(nc_hdrhdr); } 46 | 47 | void computeCalculateFields() {} 48 | 49 | std::string toString(); 50 | 51 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 52 | 53 | }; 54 | } 55 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_load.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_loadLayer 2 | 3 | #include "netcache_nc_load.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_loadLayer::getLoad_1(){ 13 | uint32_t load_1; 14 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 15 | load_1 = htonl(hdrdata->load_1); 16 | return load_1; 17 | } 18 | 19 | void Nc_loadLayer::setLoad_1(uint32_t value){ 20 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 21 | hdrdata->load_1 = htonl(value); 22 | } 23 | uint32_t Nc_loadLayer::getLoad_2(){ 24 | uint32_t load_2; 25 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 26 | load_2 = htonl(hdrdata->load_2); 27 | return load_2; 28 | } 29 | 30 | void Nc_loadLayer::setLoad_2(uint32_t value){ 31 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 32 | hdrdata->load_2 = htonl(value); 33 | } 34 | uint32_t Nc_loadLayer::getLoad_3(){ 35 | uint32_t load_3; 36 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 37 | load_3 = htonl(hdrdata->load_3); 38 | return load_3; 39 | } 40 | 41 | void Nc_loadLayer::setLoad_3(uint32_t value){ 42 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 43 | hdrdata->load_3 = htonl(value); 44 | } 45 | uint32_t Nc_loadLayer::getLoad_4(){ 46 | uint32_t load_4; 47 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 48 | load_4 = htonl(hdrdata->load_4); 49 | return load_4; 50 | } 51 | 52 | void Nc_loadLayer::setLoad_4(uint32_t value){ 53 | nc_loadhdr* hdrdata = (nc_loadhdr*)m_Data; 54 | hdrdata->load_4 = htonl(value); 55 | } 56 | void Nc_loadLayer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_loadhdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_loadLayer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_load.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_load' 2 | 3 | #ifndef P4_NC_LOAD_LAYER 4 | #define P4_NC_LOAD_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_loadhdr{ 20 | uint32_t load_1; 21 | uint32_t load_2; 22 | uint32_t load_3; 23 | uint32_t load_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_loadLayer: public Layer{ 28 | public: 29 | Nc_loadLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_LOAD;} 30 | Nc_loadLayer(){ 31 | m_DataLen = sizeof(nc_loadhdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_LOAD; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getLoad_1(); 39 | void setLoad_1(uint32_t value); 40 | uint32_t getLoad_2(); 41 | void setLoad_2(uint32_t value); 42 | uint32_t getLoad_3(); 43 | void setLoad_3(uint32_t value); 44 | uint32_t getLoad_4(); 45 | void setLoad_4(uint32_t value); 46 | 47 | inline nc_loadhdr* getNc_loadHeader() { return (nc_loadhdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_loadhdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_1.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_1Layer 2 | 3 | #include "netcache_nc_value_1.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_1Layer::getValue_1_1(){ 13 | uint32_t value_1_1; 14 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 15 | value_1_1 = htonl(hdrdata->value_1_1); 16 | return value_1_1; 17 | } 18 | 19 | void Nc_value_1Layer::setValue_1_1(uint32_t value){ 20 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 21 | hdrdata->value_1_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_1Layer::getValue_1_2(){ 24 | uint32_t value_1_2; 25 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 26 | value_1_2 = htonl(hdrdata->value_1_2); 27 | return value_1_2; 28 | } 29 | 30 | void Nc_value_1Layer::setValue_1_2(uint32_t value){ 31 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 32 | hdrdata->value_1_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_1Layer::getValue_1_3(){ 35 | uint32_t value_1_3; 36 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 37 | value_1_3 = htonl(hdrdata->value_1_3); 38 | return value_1_3; 39 | } 40 | 41 | void Nc_value_1Layer::setValue_1_3(uint32_t value){ 42 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 43 | hdrdata->value_1_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_1Layer::getValue_1_4(){ 46 | uint32_t value_1_4; 47 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 48 | value_1_4 = htonl(hdrdata->value_1_4); 49 | return value_1_4; 50 | } 51 | 52 | void Nc_value_1Layer::setValue_1_4(uint32_t value){ 53 | nc_value_1hdr* hdrdata = (nc_value_1hdr*)m_Data; 54 | hdrdata->value_1_4 = htonl(value); 55 | } 56 | void Nc_value_1Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_1hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_1Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_1.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_1' 2 | 3 | #ifndef P4_NC_VALUE_1_LAYER 4 | #define P4_NC_VALUE_1_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_1hdr{ 20 | uint32_t value_1_1; 21 | uint32_t value_1_2; 22 | uint32_t value_1_3; 23 | uint32_t value_1_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_1Layer: public Layer{ 28 | public: 29 | Nc_value_1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_1;} 30 | Nc_value_1Layer(){ 31 | m_DataLen = sizeof(nc_value_1hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_1; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_1_1(); 39 | void setValue_1_1(uint32_t value); 40 | uint32_t getValue_1_2(); 41 | void setValue_1_2(uint32_t value); 42 | uint32_t getValue_1_3(); 43 | void setValue_1_3(uint32_t value); 44 | uint32_t getValue_1_4(); 45 | void setValue_1_4(uint32_t value); 46 | 47 | inline nc_value_1hdr* getNc_value_1Header() { return (nc_value_1hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_1hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_2.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_2Layer 2 | 3 | #include "netcache_nc_value_2.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_2Layer::getValue_2_1(){ 13 | uint32_t value_2_1; 14 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 15 | value_2_1 = htonl(hdrdata->value_2_1); 16 | return value_2_1; 17 | } 18 | 19 | void Nc_value_2Layer::setValue_2_1(uint32_t value){ 20 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 21 | hdrdata->value_2_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_2Layer::getValue_2_2(){ 24 | uint32_t value_2_2; 25 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 26 | value_2_2 = htonl(hdrdata->value_2_2); 27 | return value_2_2; 28 | } 29 | 30 | void Nc_value_2Layer::setValue_2_2(uint32_t value){ 31 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 32 | hdrdata->value_2_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_2Layer::getValue_2_3(){ 35 | uint32_t value_2_3; 36 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 37 | value_2_3 = htonl(hdrdata->value_2_3); 38 | return value_2_3; 39 | } 40 | 41 | void Nc_value_2Layer::setValue_2_3(uint32_t value){ 42 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 43 | hdrdata->value_2_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_2Layer::getValue_2_4(){ 46 | uint32_t value_2_4; 47 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 48 | value_2_4 = htonl(hdrdata->value_2_4); 49 | return value_2_4; 50 | } 51 | 52 | void Nc_value_2Layer::setValue_2_4(uint32_t value){ 53 | nc_value_2hdr* hdrdata = (nc_value_2hdr*)m_Data; 54 | hdrdata->value_2_4 = htonl(value); 55 | } 56 | void Nc_value_2Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_2hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_2Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_2.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_2' 2 | 3 | #ifndef P4_NC_VALUE_2_LAYER 4 | #define P4_NC_VALUE_2_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_2hdr{ 20 | uint32_t value_2_1; 21 | uint32_t value_2_2; 22 | uint32_t value_2_3; 23 | uint32_t value_2_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_2Layer: public Layer{ 28 | public: 29 | Nc_value_2Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_2;} 30 | Nc_value_2Layer(){ 31 | m_DataLen = sizeof(nc_value_2hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_2; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_2_1(); 39 | void setValue_2_1(uint32_t value); 40 | uint32_t getValue_2_2(); 41 | void setValue_2_2(uint32_t value); 42 | uint32_t getValue_2_3(); 43 | void setValue_2_3(uint32_t value); 44 | uint32_t getValue_2_4(); 45 | void setValue_2_4(uint32_t value); 46 | 47 | inline nc_value_2hdr* getNc_value_2Header() { return (nc_value_2hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_2hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_3.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_3Layer 2 | 3 | #include "netcache_nc_value_3.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_3Layer::getValue_3_1(){ 13 | uint32_t value_3_1; 14 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 15 | value_3_1 = htonl(hdrdata->value_3_1); 16 | return value_3_1; 17 | } 18 | 19 | void Nc_value_3Layer::setValue_3_1(uint32_t value){ 20 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 21 | hdrdata->value_3_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_3Layer::getValue_3_2(){ 24 | uint32_t value_3_2; 25 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 26 | value_3_2 = htonl(hdrdata->value_3_2); 27 | return value_3_2; 28 | } 29 | 30 | void Nc_value_3Layer::setValue_3_2(uint32_t value){ 31 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 32 | hdrdata->value_3_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_3Layer::getValue_3_3(){ 35 | uint32_t value_3_3; 36 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 37 | value_3_3 = htonl(hdrdata->value_3_3); 38 | return value_3_3; 39 | } 40 | 41 | void Nc_value_3Layer::setValue_3_3(uint32_t value){ 42 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 43 | hdrdata->value_3_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_3Layer::getValue_3_4(){ 46 | uint32_t value_3_4; 47 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 48 | value_3_4 = htonl(hdrdata->value_3_4); 49 | return value_3_4; 50 | } 51 | 52 | void Nc_value_3Layer::setValue_3_4(uint32_t value){ 53 | nc_value_3hdr* hdrdata = (nc_value_3hdr*)m_Data; 54 | hdrdata->value_3_4 = htonl(value); 55 | } 56 | void Nc_value_3Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_3hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_3Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_3.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_3' 2 | 3 | #ifndef P4_NC_VALUE_3_LAYER 4 | #define P4_NC_VALUE_3_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_3hdr{ 20 | uint32_t value_3_1; 21 | uint32_t value_3_2; 22 | uint32_t value_3_3; 23 | uint32_t value_3_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_3Layer: public Layer{ 28 | public: 29 | Nc_value_3Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_3;} 30 | Nc_value_3Layer(){ 31 | m_DataLen = sizeof(nc_value_3hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_3; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_3_1(); 39 | void setValue_3_1(uint32_t value); 40 | uint32_t getValue_3_2(); 41 | void setValue_3_2(uint32_t value); 42 | uint32_t getValue_3_3(); 43 | void setValue_3_3(uint32_t value); 44 | uint32_t getValue_3_4(); 45 | void setValue_3_4(uint32_t value); 46 | 47 | inline nc_value_3hdr* getNc_value_3Header() { return (nc_value_3hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_3hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_4.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_4Layer 2 | 3 | #include "netcache_nc_value_4.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_4Layer::getValue_4_1(){ 13 | uint32_t value_4_1; 14 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 15 | value_4_1 = htonl(hdrdata->value_4_1); 16 | return value_4_1; 17 | } 18 | 19 | void Nc_value_4Layer::setValue_4_1(uint32_t value){ 20 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 21 | hdrdata->value_4_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_4Layer::getValue_4_2(){ 24 | uint32_t value_4_2; 25 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 26 | value_4_2 = htonl(hdrdata->value_4_2); 27 | return value_4_2; 28 | } 29 | 30 | void Nc_value_4Layer::setValue_4_2(uint32_t value){ 31 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 32 | hdrdata->value_4_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_4Layer::getValue_4_3(){ 35 | uint32_t value_4_3; 36 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 37 | value_4_3 = htonl(hdrdata->value_4_3); 38 | return value_4_3; 39 | } 40 | 41 | void Nc_value_4Layer::setValue_4_3(uint32_t value){ 42 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 43 | hdrdata->value_4_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_4Layer::getValue_4_4(){ 46 | uint32_t value_4_4; 47 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 48 | value_4_4 = htonl(hdrdata->value_4_4); 49 | return value_4_4; 50 | } 51 | 52 | void Nc_value_4Layer::setValue_4_4(uint32_t value){ 53 | nc_value_4hdr* hdrdata = (nc_value_4hdr*)m_Data; 54 | hdrdata->value_4_4 = htonl(value); 55 | } 56 | void Nc_value_4Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_4hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_4Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_4.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_4' 2 | 3 | #ifndef P4_NC_VALUE_4_LAYER 4 | #define P4_NC_VALUE_4_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_4hdr{ 20 | uint32_t value_4_1; 21 | uint32_t value_4_2; 22 | uint32_t value_4_3; 23 | uint32_t value_4_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_4Layer: public Layer{ 28 | public: 29 | Nc_value_4Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_4;} 30 | Nc_value_4Layer(){ 31 | m_DataLen = sizeof(nc_value_4hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_4; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_4_1(); 39 | void setValue_4_1(uint32_t value); 40 | uint32_t getValue_4_2(); 41 | void setValue_4_2(uint32_t value); 42 | uint32_t getValue_4_3(); 43 | void setValue_4_3(uint32_t value); 44 | uint32_t getValue_4_4(); 45 | void setValue_4_4(uint32_t value); 46 | 47 | inline nc_value_4hdr* getNc_value_4Header() { return (nc_value_4hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_4hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_5.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_5Layer 2 | 3 | #include "netcache_nc_value_5.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_5Layer::getValue_5_1(){ 13 | uint32_t value_5_1; 14 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 15 | value_5_1 = htonl(hdrdata->value_5_1); 16 | return value_5_1; 17 | } 18 | 19 | void Nc_value_5Layer::setValue_5_1(uint32_t value){ 20 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 21 | hdrdata->value_5_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_5Layer::getValue_5_2(){ 24 | uint32_t value_5_2; 25 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 26 | value_5_2 = htonl(hdrdata->value_5_2); 27 | return value_5_2; 28 | } 29 | 30 | void Nc_value_5Layer::setValue_5_2(uint32_t value){ 31 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 32 | hdrdata->value_5_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_5Layer::getValue_5_3(){ 35 | uint32_t value_5_3; 36 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 37 | value_5_3 = htonl(hdrdata->value_5_3); 38 | return value_5_3; 39 | } 40 | 41 | void Nc_value_5Layer::setValue_5_3(uint32_t value){ 42 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 43 | hdrdata->value_5_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_5Layer::getValue_5_4(){ 46 | uint32_t value_5_4; 47 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 48 | value_5_4 = htonl(hdrdata->value_5_4); 49 | return value_5_4; 50 | } 51 | 52 | void Nc_value_5Layer::setValue_5_4(uint32_t value){ 53 | nc_value_5hdr* hdrdata = (nc_value_5hdr*)m_Data; 54 | hdrdata->value_5_4 = htonl(value); 55 | } 56 | void Nc_value_5Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_5hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_5Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_5.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_5' 2 | 3 | #ifndef P4_NC_VALUE_5_LAYER 4 | #define P4_NC_VALUE_5_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_5hdr{ 20 | uint32_t value_5_1; 21 | uint32_t value_5_2; 22 | uint32_t value_5_3; 23 | uint32_t value_5_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_5Layer: public Layer{ 28 | public: 29 | Nc_value_5Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_5;} 30 | Nc_value_5Layer(){ 31 | m_DataLen = sizeof(nc_value_5hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_5; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_5_1(); 39 | void setValue_5_1(uint32_t value); 40 | uint32_t getValue_5_2(); 41 | void setValue_5_2(uint32_t value); 42 | uint32_t getValue_5_3(); 43 | void setValue_5_3(uint32_t value); 44 | uint32_t getValue_5_4(); 45 | void setValue_5_4(uint32_t value); 46 | 47 | inline nc_value_5hdr* getNc_value_5Header() { return (nc_value_5hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_5hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_6.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_6Layer 2 | 3 | #include "netcache_nc_value_6.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_6Layer::getValue_6_1(){ 13 | uint32_t value_6_1; 14 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 15 | value_6_1 = htonl(hdrdata->value_6_1); 16 | return value_6_1; 17 | } 18 | 19 | void Nc_value_6Layer::setValue_6_1(uint32_t value){ 20 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 21 | hdrdata->value_6_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_6Layer::getValue_6_2(){ 24 | uint32_t value_6_2; 25 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 26 | value_6_2 = htonl(hdrdata->value_6_2); 27 | return value_6_2; 28 | } 29 | 30 | void Nc_value_6Layer::setValue_6_2(uint32_t value){ 31 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 32 | hdrdata->value_6_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_6Layer::getValue_6_3(){ 35 | uint32_t value_6_3; 36 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 37 | value_6_3 = htonl(hdrdata->value_6_3); 38 | return value_6_3; 39 | } 40 | 41 | void Nc_value_6Layer::setValue_6_3(uint32_t value){ 42 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 43 | hdrdata->value_6_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_6Layer::getValue_6_4(){ 46 | uint32_t value_6_4; 47 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 48 | value_6_4 = htonl(hdrdata->value_6_4); 49 | return value_6_4; 50 | } 51 | 52 | void Nc_value_6Layer::setValue_6_4(uint32_t value){ 53 | nc_value_6hdr* hdrdata = (nc_value_6hdr*)m_Data; 54 | hdrdata->value_6_4 = htonl(value); 55 | } 56 | void Nc_value_6Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_6hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_6Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_6.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_6' 2 | 3 | #ifndef P4_NC_VALUE_6_LAYER 4 | #define P4_NC_VALUE_6_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_6hdr{ 20 | uint32_t value_6_1; 21 | uint32_t value_6_2; 22 | uint32_t value_6_3; 23 | uint32_t value_6_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_6Layer: public Layer{ 28 | public: 29 | Nc_value_6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_6;} 30 | Nc_value_6Layer(){ 31 | m_DataLen = sizeof(nc_value_6hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_6; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_6_1(); 39 | void setValue_6_1(uint32_t value); 40 | uint32_t getValue_6_2(); 41 | void setValue_6_2(uint32_t value); 42 | uint32_t getValue_6_3(); 43 | void setValue_6_3(uint32_t value); 44 | uint32_t getValue_6_4(); 45 | void setValue_6_4(uint32_t value); 46 | 47 | inline nc_value_6hdr* getNc_value_6Header() { return (nc_value_6hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_6hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_7.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_7Layer 2 | 3 | #include "netcache_nc_value_7.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_7Layer::getValue_7_1(){ 13 | uint32_t value_7_1; 14 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 15 | value_7_1 = htonl(hdrdata->value_7_1); 16 | return value_7_1; 17 | } 18 | 19 | void Nc_value_7Layer::setValue_7_1(uint32_t value){ 20 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 21 | hdrdata->value_7_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_7Layer::getValue_7_2(){ 24 | uint32_t value_7_2; 25 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 26 | value_7_2 = htonl(hdrdata->value_7_2); 27 | return value_7_2; 28 | } 29 | 30 | void Nc_value_7Layer::setValue_7_2(uint32_t value){ 31 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 32 | hdrdata->value_7_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_7Layer::getValue_7_3(){ 35 | uint32_t value_7_3; 36 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 37 | value_7_3 = htonl(hdrdata->value_7_3); 38 | return value_7_3; 39 | } 40 | 41 | void Nc_value_7Layer::setValue_7_3(uint32_t value){ 42 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 43 | hdrdata->value_7_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_7Layer::getValue_7_4(){ 46 | uint32_t value_7_4; 47 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 48 | value_7_4 = htonl(hdrdata->value_7_4); 49 | return value_7_4; 50 | } 51 | 52 | void Nc_value_7Layer::setValue_7_4(uint32_t value){ 53 | nc_value_7hdr* hdrdata = (nc_value_7hdr*)m_Data; 54 | hdrdata->value_7_4 = htonl(value); 55 | } 56 | void Nc_value_7Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_7hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_7Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_7.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_7' 2 | 3 | #ifndef P4_NC_VALUE_7_LAYER 4 | #define P4_NC_VALUE_7_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_7hdr{ 20 | uint32_t value_7_1; 21 | uint32_t value_7_2; 22 | uint32_t value_7_3; 23 | uint32_t value_7_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_7Layer: public Layer{ 28 | public: 29 | Nc_value_7Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_7;} 30 | Nc_value_7Layer(){ 31 | m_DataLen = sizeof(nc_value_7hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_7; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_7_1(); 39 | void setValue_7_1(uint32_t value); 40 | uint32_t getValue_7_2(); 41 | void setValue_7_2(uint32_t value); 42 | uint32_t getValue_7_3(); 43 | void setValue_7_3(uint32_t value); 44 | uint32_t getValue_7_4(); 45 | void setValue_7_4(uint32_t value); 46 | 47 | inline nc_value_7hdr* getNc_value_7Header() { return (nc_value_7hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_7hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_8.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleNc_value_8Layer 2 | 3 | #include "netcache_nc_value_8.h" 4 | #include "PayloadLayer.h" 5 | #include "IpUtils.h" 6 | #include "Logger.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pcpp{ 12 | uint32_t Nc_value_8Layer::getValue_8_1(){ 13 | uint32_t value_8_1; 14 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 15 | value_8_1 = htonl(hdrdata->value_8_1); 16 | return value_8_1; 17 | } 18 | 19 | void Nc_value_8Layer::setValue_8_1(uint32_t value){ 20 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 21 | hdrdata->value_8_1 = htonl(value); 22 | } 23 | uint32_t Nc_value_8Layer::getValue_8_2(){ 24 | uint32_t value_8_2; 25 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 26 | value_8_2 = htonl(hdrdata->value_8_2); 27 | return value_8_2; 28 | } 29 | 30 | void Nc_value_8Layer::setValue_8_2(uint32_t value){ 31 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 32 | hdrdata->value_8_2 = htonl(value); 33 | } 34 | uint32_t Nc_value_8Layer::getValue_8_3(){ 35 | uint32_t value_8_3; 36 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 37 | value_8_3 = htonl(hdrdata->value_8_3); 38 | return value_8_3; 39 | } 40 | 41 | void Nc_value_8Layer::setValue_8_3(uint32_t value){ 42 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 43 | hdrdata->value_8_3 = htonl(value); 44 | } 45 | uint32_t Nc_value_8Layer::getValue_8_4(){ 46 | uint32_t value_8_4; 47 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 48 | value_8_4 = htonl(hdrdata->value_8_4); 49 | return value_8_4; 50 | } 51 | 52 | void Nc_value_8Layer::setValue_8_4(uint32_t value){ 53 | nc_value_8hdr* hdrdata = (nc_value_8hdr*)m_Data; 54 | hdrdata->value_8_4 = htonl(value); 55 | } 56 | void Nc_value_8Layer::parseNextLayer(){ 57 | if (m_DataLen <= sizeof(nc_value_8hdr)) 58 | return; 59 | 60 | } 61 | 62 | std::string Nc_value_8Layer::toString(){ return ""; } 63 | 64 | } -------------------------------------------------------------------------------- /samples/netcache/output/pcapplusplus/netcache_nc_value_8.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_value_8' 2 | 3 | #ifndef P4_NC_VALUE_8_LAYER 4 | #define P4_NC_VALUE_8_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_value_8hdr{ 20 | uint32_t value_8_1; 21 | uint32_t value_8_2; 22 | uint32_t value_8_3; 23 | uint32_t value_8_4; 24 | }; 25 | 26 | #pragma pack(pop) 27 | class Nc_value_8Layer: public Layer{ 28 | public: 29 | Nc_value_8Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_VALUE_8;} 30 | Nc_value_8Layer(){ 31 | m_DataLen = sizeof(nc_value_8hdr); 32 | m_Data = new uint8_t[m_DataLen]; 33 | memset(m_Data, 0, m_DataLen); 34 | m_Protocol = P4_NC_VALUE_8; 35 | } 36 | 37 | // Getters and Setters for fields 38 | uint32_t getValue_8_1(); 39 | void setValue_8_1(uint32_t value); 40 | uint32_t getValue_8_2(); 41 | void setValue_8_2(uint32_t value); 42 | uint32_t getValue_8_3(); 43 | void setValue_8_3(uint32_t value); 44 | uint32_t getValue_8_4(); 45 | void setValue_8_4(uint32_t value); 46 | 47 | inline nc_value_8hdr* getNc_value_8Header() { return (nc_value_8hdr*)m_Data; } 48 | 49 | void parseNextLayer(); 50 | 51 | inline size_t getHeaderLen() { return sizeof(nc_value_8hdr); } 52 | 53 | void computeCalculateFields() {} 54 | 55 | std::string toString(); 56 | 57 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 58 | 59 | }; 60 | } 61 | #endif -------------------------------------------------------------------------------- /samples/netcache/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/netcache/output/wireshark/netcache_1_ipv4.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/netcache/output/wireshark/netcache_2_tcp.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/netcache/output/wireshark/netcache_3_udp.lua') 4 | dofile('/home/raj/workspace/p4-traffictool/samples/netcache/output/wireshark/netcache_4_nc_hdr.lua') 5 | dofile('/home/raj/workspace/p4-traffictool/samples/netcache/output/wireshark/netcache_5_nc_load.lua') 6 | -------------------------------------------------------------------------------- /samples/netcache/output/wireshark/netcache_2_tcp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_tcp = Proto('p4_tcp','P4_TCPProtocol') 3 | 4 | -- protocol fields 5 | local p4_tcp_srcPort = ProtoField.string('p4_tcp.srcPort','srcPort') 6 | local p4_tcp_dstPort = ProtoField.string('p4_tcp.dstPort','dstPort') 7 | local p4_tcp_seqNo = ProtoField.string('p4_tcp.seqNo','seqNo') 8 | local p4_tcp_ackNo = ProtoField.string('p4_tcp.ackNo','ackNo') 9 | local p4_tcp_dataOffset = ProtoField.string('p4_tcp.dataOffset','dataOffset') 10 | local p4_tcp_res = ProtoField.string('p4_tcp.res','res') 11 | local p4_tcp_ecn = ProtoField.string('p4_tcp.ecn','ecn') 12 | local p4_tcp_ctrl = ProtoField.string('p4_tcp.ctrl','ctrl') 13 | local p4_tcp_window = ProtoField.string('p4_tcp.window','window') 14 | local p4_tcp_checksum = ProtoField.string('p4_tcp.checksum','checksum') 15 | local p4_tcp_urgentPtr = ProtoField.string('p4_tcp.urgentPtr','urgentPtr') 16 | p4_tcp.fields = {p4_tcp_srcPort, p4_tcp_dstPort, p4_tcp_seqNo, p4_tcp_ackNo, p4_tcp_dataOffset, p4_tcp_res, p4_tcp_ecn, p4_tcp_ctrl, p4_tcp_window, p4_tcp_checksum, p4_tcp_urgentPtr} 17 | 18 | 19 | -- protocol dissector function 20 | function p4_tcp.dissector(buffer,pinfo,tree) 21 | pinfo.cols.protocol = 'P4_TCP' 22 | local subtree = tree:add(p4_tcp,buffer(),'P4_TCP Protocol Data') 23 | subtree:add(p4_tcp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 24 | subtree:add(p4_tcp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 25 | subtree:add(p4_tcp_seqNo,tostring(buffer(4,4):bitfield(0,32))) 26 | subtree:add(p4_tcp_ackNo,tostring(buffer(8,4):bitfield(0,32))) 27 | subtree:add(p4_tcp_dataOffset,tostring(buffer(12,1):bitfield(0,4))) 28 | subtree:add(p4_tcp_res,tostring(buffer(12,1):bitfield(4,3))) 29 | subtree:add(p4_tcp_ecn,tostring(buffer(12,2):bitfield(7,3))) 30 | subtree:add(p4_tcp_ctrl,tostring(buffer(13,1):bitfield(2,6))) 31 | subtree:add(p4_tcp_window,tostring(buffer(14,2):bitfield(0,16))) 32 | subtree:add(p4_tcp_checksum,tostring(buffer(16,2):bitfield(0,16))) 33 | subtree:add(p4_tcp_urgentPtr,tostring(buffer(18,2):bitfield(0,16))) 34 | 35 | end 36 | 37 | print( (require 'debug').getinfo(1).source ) 38 | 39 | -- creation of table for next layer(if required) 40 | 41 | -- No table required 42 | 43 | -- protocol registration 44 | my_table = DissectorTable.get('p4_ipv4.protocol') 45 | my_table:add(0x06,p4_tcp) 46 | -------------------------------------------------------------------------------- /samples/netcache/output/wireshark/netcache_3_udp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_udp = Proto('p4_udp','P4_UDPProtocol') 3 | 4 | -- protocol fields 5 | local p4_udp_srcPort = ProtoField.string('p4_udp.srcPort','srcPort') 6 | local p4_udp_dstPort = ProtoField.string('p4_udp.dstPort','dstPort') 7 | local p4_udp_len = ProtoField.string('p4_udp.len','len') 8 | local p4_udp_checksum = ProtoField.string('p4_udp.checksum','checksum') 9 | p4_udp.fields = {p4_udp_srcPort, p4_udp_dstPort, p4_udp_len, p4_udp_checksum} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_udp.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_UDP' 15 | local subtree = tree:add(p4_udp,buffer(),'P4_UDP Protocol Data') 16 | subtree:add(p4_udp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_udp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_udp_len,tostring(buffer(4,2):bitfield(0,16))) 19 | subtree:add(p4_udp_checksum,tostring(buffer(6,2):bitfield(0,16))) 20 | local mydissectortable = DissectorTable.get('p4_udp.dstPort') 21 | mydissectortable:try(buffer(2,2):bitfield(0,16), buffer:range(8):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_udp.dstPort','P4_UDP.DSTPORT',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('p4_ipv4.protocol') 32 | my_table:add(0x11,p4_udp) 33 | -------------------------------------------------------------------------------- /samples/netcache/output/wireshark/netcache_4_nc_hdr.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_nc_hdr = Proto('p4_nc_hdr','P4_NC_HDRProtocol') 3 | 4 | -- protocol fields 5 | local p4_nc_hdr_op = ProtoField.string('p4_nc_hdr.op','op') 6 | local p4_nc_hdr_key = ProtoField.string('p4_nc_hdr.key','key') 7 | p4_nc_hdr.fields = {p4_nc_hdr_op, p4_nc_hdr_key} 8 | 9 | 10 | -- protocol dissector function 11 | function p4_nc_hdr.dissector(buffer,pinfo,tree) 12 | pinfo.cols.protocol = 'P4_NC_HDR' 13 | local subtree = tree:add(p4_nc_hdr,buffer(),'P4_NC_HDR Protocol Data') 14 | subtree:add(p4_nc_hdr_op,tostring(buffer(0,1):bitfield(0,8))) 15 | subtree:add(p4_nc_hdr_key,tostring(buffer(1,8):bitfield(0,64))) 16 | local mydissectortable = DissectorTable.get('p4_nc_hdr.op') 17 | mydissectortable:try(buffer(0,1):bitfield(0,8), buffer:range(9):tvb(),pinfo,tree) 18 | 19 | end 20 | 21 | print( (require 'debug').getinfo(1).source ) 22 | 23 | -- creation of table for next layer(if required) 24 | local newdissectortable = DissectorTable.new('p4_nc_hdr.op','P4_NC_HDR.OP',ftypes.STRING) 25 | 26 | -- protocol registration 27 | my_table = DissectorTable.get('p4_udp.dstPort') 28 | my_table:add(0x22b8,p4_nc_hdr) 29 | -------------------------------------------------------------------------------- /samples/netcache/output/wireshark/netcache_5_nc_load.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_nc_load = Proto('p4_nc_load','P4_NC_LOADProtocol') 3 | 4 | -- protocol fields 5 | local p4_nc_load_load_1 = ProtoField.string('p4_nc_load.load_1','load_1') 6 | local p4_nc_load_load_2 = ProtoField.string('p4_nc_load.load_2','load_2') 7 | local p4_nc_load_load_3 = ProtoField.string('p4_nc_load.load_3','load_3') 8 | local p4_nc_load_load_4 = ProtoField.string('p4_nc_load.load_4','load_4') 9 | p4_nc_load.fields = {p4_nc_load_load_1, p4_nc_load_load_2, p4_nc_load_load_3, p4_nc_load_load_4} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_nc_load.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_NC_LOAD' 15 | local subtree = tree:add(p4_nc_load,buffer(),'P4_NC_LOAD Protocol Data') 16 | subtree:add(p4_nc_load_load_1,tostring(buffer(0,4):bitfield(0,32))) 17 | subtree:add(p4_nc_load_load_2,tostring(buffer(4,4):bitfield(0,32))) 18 | subtree:add(p4_nc_load_load_3,tostring(buffer(8,4):bitfield(0,32))) 19 | subtree:add(p4_nc_load_load_4,tostring(buffer(12,4):bitfield(0,32))) 20 | 21 | end 22 | 23 | print( (require 'debug').getinfo(1).source ) 24 | 25 | -- creation of table for next layer(if required) 26 | 27 | -- No table required 28 | 29 | -- protocol registration 30 | my_table = DissectorTable.get('p4_nc_hdr.op') 31 | my_table:add(0x02,p4_nc_load) 32 | -------------------------------------------------------------------------------- /samples/netchain/includes/checksum.p4: -------------------------------------------------------------------------------- 1 | field_list ipv4_field_list { 2 | ipv4.version; 3 | ipv4.ihl; 4 | ipv4.diffserv; 5 | ipv4.totalLen; 6 | ipv4.identification; 7 | ipv4.flags; 8 | ipv4.fragOffset; 9 | ipv4.ttl; 10 | ipv4.protocol; 11 | ipv4.srcAddr; 12 | ipv4.dstAddr; 13 | } 14 | field_list_calculation ipv4_chksum_calc { 15 | input { 16 | ipv4_field_list; 17 | } 18 | algorithm : csum16; 19 | output_width: 16; 20 | } 21 | calculated_field ipv4.hdrChecksum { 22 | update ipv4_chksum_calc; 23 | } 24 | 25 | field_list udp_checksum_list { 26 | // IPv4 Pseudo Header Format. Must modify for IPv6 support. 27 | ipv4.srcAddr; 28 | ipv4.dstAddr; 29 | 8'0; 30 | ipv4.protocol; 31 | udp.len; 32 | udp.srcPort; 33 | udp.dstPort; 34 | udp.len; 35 | // udp.checksum; 36 | payload; 37 | } 38 | field_list_calculation udp_checksum { 39 | input { 40 | udp_checksum_list; 41 | } 42 | algorithm : csum16; 43 | output_width : 16; 44 | } 45 | calculated_field udp.checksum { 46 | update udp_checksum; 47 | } 48 | -------------------------------------------------------------------------------- /samples/netchain/includes/defines.p4: -------------------------------------------------------------------------------- 1 | #define SEQUENCE_REG_SIZE 4096 2 | #define VALUE_REG_SIZE 4096 3 | 4 | #define NUM_CACHE 128 5 | #define NC_PORT 8888 6 | #define REPLY_PORT 8889 7 | #define NC_READ_REQUEST 10 8 | #define NC_READ_REPLY 11 9 | #define NC_WRITE_REQUEST 12 10 | #define NC_WRITE_REPLY 13 11 | #define DROP_PORT 9999 12 | #define END_OF_CHAIN 0 13 | #define MAX_LENGTH_OF_CHAIN 10 14 | #define HEAD_NODE 100 15 | #define REPLICA_NODE 101 16 | #define TAIL_NODE 102 17 | #define DROPPED 100 18 | -------------------------------------------------------------------------------- /samples/netchain/includes/headers.p4: -------------------------------------------------------------------------------- 1 | header_type ethernet_t { 2 | fields { 3 | dstAddr : 48; 4 | srcAddr : 48; 5 | etherType : 16; 6 | } 7 | } 8 | header ethernet_t ethernet; 9 | 10 | header_type ipv4_t { 11 | fields { 12 | version : 4; 13 | ihl : 4; 14 | diffserv : 8; 15 | totalLen : 16; 16 | identification : 16; 17 | flags : 3; 18 | fragOffset : 13; 19 | ttl : 8; 20 | protocol : 8; 21 | hdrChecksum : 16; 22 | srcAddr : 32; 23 | dstAddr: 32; 24 | } 25 | } 26 | header ipv4_t ipv4; 27 | 28 | header_type tcp_t { 29 | fields { 30 | srcPort : 16; 31 | dstPort : 16; 32 | seqNo : 32; 33 | ackNo : 32; 34 | dataOffset : 4; 35 | res : 3; 36 | ecn : 3; 37 | ctrl : 6; 38 | window : 16; 39 | checksum : 16; 40 | urgentPtr : 16; 41 | } 42 | } 43 | header tcp_t tcp; 44 | 45 | header_type udp_t { 46 | fields { 47 | srcPort : 16; 48 | dstPort : 16; 49 | len : 16; 50 | checksum : 16; 51 | } 52 | } 53 | header udp_t udp; 54 | 55 | header_type overlay_t { 56 | fields { 57 | swip: 32; 58 | } 59 | } 60 | header overlay_t overlay [MAX_LENGTH_OF_CHAIN]; 61 | 62 | header_type nc_hdr_t { 63 | fields { 64 | op: 8; 65 | sc: 8; 66 | seq: 16; 67 | key: 64; 68 | value: 64; 69 | vgroup: 16; 70 | } 71 | 72 | } 73 | header nc_hdr_t nc_hdr; -------------------------------------------------------------------------------- /samples/netchain/includes/parsers.p4: -------------------------------------------------------------------------------- 1 | parser start { 2 | return parse_ethernet; 3 | } 4 | 5 | #define ETHER_TYPE_IPV4 0x0800 6 | parser parse_ethernet { 7 | extract (ethernet); 8 | return select (latest.etherType) { 9 | ETHER_TYPE_IPV4: parse_ipv4; 10 | default: ingress; 11 | } 12 | } 13 | 14 | #define IPV4_PROTOCOL_TCP 6 15 | #define IPV4_PROTOCOL_UDP 17 16 | parser parse_ipv4 { 17 | extract(ipv4); 18 | return select (latest.protocol) { 19 | IPV4_PROTOCOL_TCP: parse_tcp; 20 | IPV4_PROTOCOL_UDP: parse_udp; 21 | default: ingress; 22 | } 23 | } 24 | 25 | parser parse_tcp { 26 | extract (tcp); 27 | return ingress; 28 | } 29 | 30 | parser parse_udp { 31 | extract (udp); 32 | return select (latest.dstPort) { 33 | NC_PORT: parse_overlay; 34 | REPLY_PORT: parse_overlay; 35 | default: ingress; 36 | } 37 | } 38 | 39 | parser parse_overlay { 40 | extract (overlay[next]); 41 | return select (latest.swip) { 42 | END_OF_CHAIN: parse_nc_hdr; 43 | default: parse_overlay; 44 | } 45 | } 46 | 47 | parser parse_nc_hdr { 48 | extract (nc_hdr); 49 | return select(latest.op) { 50 | NC_READ_REQUEST: ingress; 51 | NC_WRITE_REQUEST: ingress; 52 | default: ingress; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /samples/netchain/output/pcapplusplus/netchain_nc_hdr.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'nc_hdr' 2 | 3 | #ifndef P4_NC_HDR_LAYER 4 | #define P4_NC_HDR_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct nc_hdrhdr{ 20 | uint8_t op; 21 | uint8_t sc; 22 | uint16_t seq; 23 | uint64_t key; 24 | uint64_t value; 25 | uint16_t vgroup; 26 | }; 27 | 28 | #pragma pack(pop) 29 | class Nc_hdrLayer: public Layer{ 30 | public: 31 | Nc_hdrLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_NC_HDR;} 32 | Nc_hdrLayer(){ 33 | m_DataLen = sizeof(nc_hdrhdr); 34 | m_Data = new uint8_t[m_DataLen]; 35 | memset(m_Data, 0, m_DataLen); 36 | m_Protocol = P4_NC_HDR; 37 | } 38 | 39 | // Getters and Setters for fields 40 | uint8_t getOp(); 41 | void setOp(uint8_t value); 42 | uint8_t getSc(); 43 | void setSc(uint8_t value); 44 | uint16_t getSeq(); 45 | void setSeq(uint16_t value); 46 | uint64_t getKey(); 47 | void setKey(uint64_t value); 48 | uint64_t getValue(); 49 | void setValue(uint64_t value); 50 | uint16_t getVgroup(); 51 | void setVgroup(uint16_t value); 52 | 53 | inline nc_hdrhdr* getNc_hdrHeader() { return (nc_hdrhdr*)m_Data; } 54 | 55 | void parseNextLayer(); 56 | 57 | inline size_t getHeaderLen() { return sizeof(nc_hdrhdr); } 58 | 59 | void computeCalculateFields() {} 60 | 61 | std::string toString(); 62 | 63 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 64 | 65 | }; 66 | } 67 | #endif -------------------------------------------------------------------------------- /samples/netchain/output/pcapplusplus/netchain_overlay.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleOverlayLayer 2 | 3 | #include "netchain_overlay.h" 4 | #include "netchain_nc_hdr.h" 5 | #include "netchain_overlay.h" 6 | #include "PayloadLayer.h" 7 | #include "IpUtils.h" 8 | #include "Logger.h" 9 | #include 10 | #include 11 | #include 12 | 13 | namespace pcpp{ 14 | uint32_t OverlayLayer::getSwip(){ 15 | uint32_t swip; 16 | overlayhdr* hdrdata = (overlayhdr*)m_Data; 17 | swip = htonl(hdrdata->swip); 18 | return swip; 19 | } 20 | 21 | void OverlayLayer::setSwip(uint32_t value){ 22 | overlayhdr* hdrdata = (overlayhdr*)m_Data; 23 | hdrdata->swip = htonl(value); 24 | } 25 | void OverlayLayer::parseNextLayer(){ 26 | if (m_DataLen <= sizeof(overlayhdr)) 27 | return; 28 | 29 | uint32_t swip = OverlayLayer::getSwip(); 30 | if (swip == 0x00000000) 31 | m_NextLayer = new Nc_hdrLayer(m_Data+sizeof(overlayhdr), m_DataLen - sizeof(overlayhdr), this, m_Packet); 32 | else if (swip == 0xfault) 33 | m_NextLayer = new OverlayLayer(m_Data+sizeof(overlayhdr), m_DataLen - sizeof(overlayhdr), this, m_Packet); 34 | m_NextLayer = new PayloadLayer(m_Data + sizeof(overlayhdr), m_DataLen - sizeof(overlayhdr), this, m_Packet); 35 | } 36 | 37 | std::string OverlayLayer::toString(){ return ""; } 38 | 39 | } -------------------------------------------------------------------------------- /samples/netchain/output/pcapplusplus/netchain_overlay.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'overlay' 2 | 3 | #ifndef P4_OVERLAY_LAYER 4 | #define P4_OVERLAY_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct overlayhdr{ 20 | uint32_t swip; 21 | }; 22 | 23 | #pragma pack(pop) 24 | class OverlayLayer: public Layer{ 25 | public: 26 | OverlayLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_OVERLAY;} 27 | OverlayLayer(){ 28 | m_DataLen = sizeof(overlayhdr); 29 | m_Data = new uint8_t[m_DataLen]; 30 | memset(m_Data, 0, m_DataLen); 31 | m_Protocol = P4_OVERLAY; 32 | } 33 | 34 | // Getters and Setters for fields 35 | uint32_t getSwip(); 36 | void setSwip(uint32_t value); 37 | 38 | inline overlayhdr* getOverlayHeader() { return (overlayhdr*)m_Data; } 39 | 40 | void parseNextLayer(); 41 | 42 | inline size_t getHeaderLen() { return sizeof(overlayhdr); } 43 | 44 | void computeCalculateFields() {} 45 | 46 | std::string toString(); 47 | 48 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 49 | 50 | }; 51 | } 52 | #endif -------------------------------------------------------------------------------- /samples/netchain/output/scapy/netchain.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class Nc_hdr(Packet): 5 | name = 'nc_hdr' 6 | fields_desc = [ 7 | XByteField('op', 0), 8 | XByteField('sc', 0), 9 | XShortField('seq', 0), 10 | XLongField('key', 0), 11 | XLongField('value', 0), 12 | XShortField('vgroup', 0), 13 | ] 14 | class Overlay(Packet): 15 | name = 'overlay' 16 | fields_desc = [ 17 | XIntField('swip', 0), 18 | ] 19 | 20 | def guess_payload_class(self, payload): 21 | if (self.swip == 0x00000000): 22 | return Nc_hdr 23 | elif (self.swip == 0xfault): 24 | return Overlay 25 | else: 26 | return Packet.guess_payload_class(self, payload) 27 | 28 | 29 | ## remaining bindings 30 | bind_layers(Ether, IP, type=0x0800) 31 | bind_layers(IP, TCP, proto=0x06) 32 | bind_layers(IP, UDP, proto=0x11) 33 | bind_layers(UDP, Overlay, dport=0x22b8) 34 | bind_layers(UDP, Overlay, dport=0x22b9) 35 | 36 | ##packet_list 37 | 38 | #No possible packets which can be parsed to the final state -------------------------------------------------------------------------------- /samples/netchain/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/netchain/output/wireshark/netchain_1_ipv4.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/netchain/output/wireshark/netchain_2_tcp.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/netchain/output/wireshark/netchain_3_udp.lua') 4 | dofile('/home/raj/workspace/p4-traffictool/samples/netchain/output/wireshark/netchain_4_overlay.lua') 5 | dofile('/home/raj/workspace/p4-traffictool/samples/netchain/output/wireshark/netchain_5_nc_hdr.lua') 6 | -------------------------------------------------------------------------------- /samples/netchain/output/wireshark/netchain_2_tcp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_tcp = Proto('p4_tcp','P4_TCPProtocol') 3 | 4 | -- protocol fields 5 | local p4_tcp_srcPort = ProtoField.string('p4_tcp.srcPort','srcPort') 6 | local p4_tcp_dstPort = ProtoField.string('p4_tcp.dstPort','dstPort') 7 | local p4_tcp_seqNo = ProtoField.string('p4_tcp.seqNo','seqNo') 8 | local p4_tcp_ackNo = ProtoField.string('p4_tcp.ackNo','ackNo') 9 | local p4_tcp_dataOffset = ProtoField.string('p4_tcp.dataOffset','dataOffset') 10 | local p4_tcp_res = ProtoField.string('p4_tcp.res','res') 11 | local p4_tcp_ecn = ProtoField.string('p4_tcp.ecn','ecn') 12 | local p4_tcp_ctrl = ProtoField.string('p4_tcp.ctrl','ctrl') 13 | local p4_tcp_window = ProtoField.string('p4_tcp.window','window') 14 | local p4_tcp_checksum = ProtoField.string('p4_tcp.checksum','checksum') 15 | local p4_tcp_urgentPtr = ProtoField.string('p4_tcp.urgentPtr','urgentPtr') 16 | p4_tcp.fields = {p4_tcp_srcPort, p4_tcp_dstPort, p4_tcp_seqNo, p4_tcp_ackNo, p4_tcp_dataOffset, p4_tcp_res, p4_tcp_ecn, p4_tcp_ctrl, p4_tcp_window, p4_tcp_checksum, p4_tcp_urgentPtr} 17 | 18 | 19 | -- protocol dissector function 20 | function p4_tcp.dissector(buffer,pinfo,tree) 21 | pinfo.cols.protocol = 'P4_TCP' 22 | local subtree = tree:add(p4_tcp,buffer(),'P4_TCP Protocol Data') 23 | subtree:add(p4_tcp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 24 | subtree:add(p4_tcp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 25 | subtree:add(p4_tcp_seqNo,tostring(buffer(4,4):bitfield(0,32))) 26 | subtree:add(p4_tcp_ackNo,tostring(buffer(8,4):bitfield(0,32))) 27 | subtree:add(p4_tcp_dataOffset,tostring(buffer(12,1):bitfield(0,4))) 28 | subtree:add(p4_tcp_res,tostring(buffer(12,1):bitfield(4,3))) 29 | subtree:add(p4_tcp_ecn,tostring(buffer(12,2):bitfield(7,3))) 30 | subtree:add(p4_tcp_ctrl,tostring(buffer(13,1):bitfield(2,6))) 31 | subtree:add(p4_tcp_window,tostring(buffer(14,2):bitfield(0,16))) 32 | subtree:add(p4_tcp_checksum,tostring(buffer(16,2):bitfield(0,16))) 33 | subtree:add(p4_tcp_urgentPtr,tostring(buffer(18,2):bitfield(0,16))) 34 | 35 | end 36 | 37 | print( (require 'debug').getinfo(1).source ) 38 | 39 | -- creation of table for next layer(if required) 40 | 41 | -- No table required 42 | 43 | -- protocol registration 44 | my_table = DissectorTable.get('p4_ipv4.protocol') 45 | my_table:add(0x06,p4_tcp) 46 | -------------------------------------------------------------------------------- /samples/netchain/output/wireshark/netchain_3_udp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_udp = Proto('p4_udp','P4_UDPProtocol') 3 | 4 | -- protocol fields 5 | local p4_udp_srcPort = ProtoField.string('p4_udp.srcPort','srcPort') 6 | local p4_udp_dstPort = ProtoField.string('p4_udp.dstPort','dstPort') 7 | local p4_udp_len = ProtoField.string('p4_udp.len','len') 8 | local p4_udp_checksum = ProtoField.string('p4_udp.checksum','checksum') 9 | p4_udp.fields = {p4_udp_srcPort, p4_udp_dstPort, p4_udp_len, p4_udp_checksum} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_udp.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_UDP' 15 | local subtree = tree:add(p4_udp,buffer(),'P4_UDP Protocol Data') 16 | subtree:add(p4_udp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_udp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_udp_len,tostring(buffer(4,2):bitfield(0,16))) 19 | subtree:add(p4_udp_checksum,tostring(buffer(6,2):bitfield(0,16))) 20 | local mydissectortable = DissectorTable.get('p4_udp.dstPort') 21 | mydissectortable:try(buffer(2,2):bitfield(0,16), buffer:range(8):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_udp.dstPort','P4_UDP.DSTPORT',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('p4_ipv4.protocol') 32 | my_table:add(0x11,p4_udp) 33 | -------------------------------------------------------------------------------- /samples/netchain/output/wireshark/netchain_4_overlay.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_overlay = Proto('p4_overlay','P4_OVERLAYProtocol') 3 | 4 | -- protocol fields 5 | local p4_overlay_swip = ProtoField.string('p4_overlay.swip','swip') 6 | p4_overlay.fields = {p4_overlay_swip} 7 | 8 | 9 | -- protocol dissector function 10 | function p4_overlay.dissector(buffer,pinfo,tree) 11 | pinfo.cols.protocol = 'P4_OVERLAY' 12 | local subtree = tree:add(p4_overlay,buffer(),'P4_OVERLAY Protocol Data') 13 | subtree:add(p4_overlay_swip,tostring(buffer(0,4):bitfield(0,32))) 14 | local mydissectortable = DissectorTable.get('p4_overlay.swip') 15 | mydissectortable:try(buffer(0,4):bitfield(0,32), buffer:range(4):tvb(),pinfo,tree) 16 | 17 | end 18 | 19 | print( (require 'debug').getinfo(1).source ) 20 | 21 | -- creation of table for next layer(if required) 22 | local newdissectortable = DissectorTable.new('p4_overlay.swip','P4_OVERLAY.SWIP',ftypes.STRING) 23 | 24 | -- protocol registration 25 | my_table = DissectorTable.get('p4_overlay.swip') 26 | my_table:add(0x0,p4_overlay) 27 | my_table = DissectorTable.get('p4_udp.dstPort') 28 | my_table:add(0x22b8,p4_overlay) 29 | my_table = DissectorTable.get('p4_udp.dstPort') 30 | my_table:add(0x22b9,p4_overlay) 31 | -------------------------------------------------------------------------------- /samples/netchain/output/wireshark/netchain_5_nc_hdr.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_nc_hdr = Proto('p4_nc_hdr','P4_NC_HDRProtocol') 3 | 4 | -- protocol fields 5 | local p4_nc_hdr_op = ProtoField.string('p4_nc_hdr.op','op') 6 | local p4_nc_hdr_sc = ProtoField.string('p4_nc_hdr.sc','sc') 7 | local p4_nc_hdr_seq = ProtoField.string('p4_nc_hdr.seq','seq') 8 | local p4_nc_hdr_key = ProtoField.string('p4_nc_hdr.key','key') 9 | local p4_nc_hdr_value = ProtoField.string('p4_nc_hdr.value','value') 10 | local p4_nc_hdr_vgroup = ProtoField.string('p4_nc_hdr.vgroup','vgroup') 11 | p4_nc_hdr.fields = {p4_nc_hdr_op, p4_nc_hdr_sc, p4_nc_hdr_seq, p4_nc_hdr_key, p4_nc_hdr_value, p4_nc_hdr_vgroup} 12 | 13 | 14 | -- protocol dissector function 15 | function p4_nc_hdr.dissector(buffer,pinfo,tree) 16 | pinfo.cols.protocol = 'P4_NC_HDR' 17 | local subtree = tree:add(p4_nc_hdr,buffer(),'P4_NC_HDR Protocol Data') 18 | subtree:add(p4_nc_hdr_op,tostring(buffer(0,1):bitfield(0,8))) 19 | subtree:add(p4_nc_hdr_sc,tostring(buffer(1,1):bitfield(0,8))) 20 | subtree:add(p4_nc_hdr_seq,tostring(buffer(2,2):bitfield(0,16))) 21 | subtree:add(p4_nc_hdr_key,tostring(buffer(4,8):bitfield(0,64))) 22 | subtree:add(p4_nc_hdr_value,tostring(buffer(12,8):bitfield(0,64))) 23 | subtree:add(p4_nc_hdr_vgroup,tostring(buffer(20,2):bitfield(0,16))) 24 | 25 | end 26 | 27 | print( (require 'debug').getinfo(1).source ) 28 | 29 | -- creation of table for next layer(if required) 30 | 31 | -- No table required 32 | 33 | -- protocol registration 34 | my_table = DissectorTable.get('p4_overlay.swip') 35 | my_table:add(0x00000000,p4_nc_hdr) 36 | -------------------------------------------------------------------------------- /samples/netchain/routing.p4: -------------------------------------------------------------------------------- 1 | action set_egress(egress_spec) { 2 | modify_field(standard_metadata.egress_spec, egress_spec); 3 | add_to_field(ipv4.ttl, -1); 4 | } 5 | 6 | @pragma stage 11 7 | table ipv4_route { 8 | reads { 9 | ipv4.dstAddr : exact; 10 | } 11 | actions { 12 | set_egress; 13 | } 14 | size : 8192; 15 | } 16 | 17 | action ethernet_set_mac_act (smac, dmac) { 18 | modify_field (ethernet.srcAddr, smac); 19 | modify_field (ethernet.dstAddr, dmac); 20 | } 21 | table ethernet_set_mac { 22 | reads { 23 | standard_metadata.egress_port: exact; 24 | } 25 | actions { 26 | ethernet_set_mac_act; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/p4paxos/includes/headers.p4: -------------------------------------------------------------------------------- 1 | #ifndef _HEADERS_P4_ 2 | #define _HEADERS_P4_ 3 | 4 | // standard headers 5 | 6 | header_type ethernet_t { 7 | fields { 8 | dstAddr : 48; 9 | srcAddr : 48; 10 | etherType : 16; 11 | } 12 | } 13 | 14 | header ethernet_t ethernet; 15 | 16 | header_type ipv4_t { 17 | fields { 18 | version : 4; 19 | ihl : 4; 20 | diffserv : 8; 21 | totalLen : 16; 22 | identification : 16; 23 | flags : 3; 24 | fragOffset : 13; 25 | ttl : 8; 26 | protocol : 8; 27 | hdrChecksum : 16; 28 | srcAddr : 32; 29 | dstAddr: 32; 30 | } 31 | } 32 | 33 | header ipv4_t ipv4; 34 | 35 | field_list ipv4_checksum_list { 36 | ipv4.version; 37 | ipv4.ihl; 38 | ipv4.diffserv; 39 | ipv4.totalLen; 40 | ipv4.identification; 41 | ipv4.flags; 42 | ipv4.fragOffset; 43 | ipv4.ttl; 44 | ipv4.protocol; 45 | ipv4.srcAddr; 46 | ipv4.dstAddr; 47 | } 48 | 49 | field_list_calculation ipv4_checksum { 50 | input { 51 | ipv4_checksum_list; 52 | } 53 | algorithm : csum16; 54 | output_width : 16; 55 | } 56 | 57 | calculated_field ipv4.hdrChecksum { 58 | verify ipv4_checksum; 59 | update ipv4_checksum; 60 | } 61 | 62 | header_type udp_t { 63 | fields { 64 | srcPort : 16; 65 | dstPort : 16; 66 | length_ : 16; 67 | checksum : 16; 68 | } 69 | } 70 | 71 | header udp_t udp; 72 | 73 | 74 | field_list udp_checksum_list { 75 | ipv4.srcAddr; 76 | ipv4.dstAddr; 77 | 8'0; 78 | ipv4.protocol; 79 | udp.length_; 80 | udp.srcPort; 81 | udp.dstPort; 82 | udp.length_; 83 | payload; 84 | } 85 | 86 | field_list_calculation udp_checksum { 87 | input { 88 | udp_checksum_list; 89 | } 90 | algorithm : csum16; 91 | output_width : 16; 92 | } 93 | 94 | calculated_field udp.checksum { 95 | verify udp_checksum if (valid(udp)); 96 | update udp_checksum if (valid(udp)); 97 | } 98 | 99 | 100 | #endif -------------------------------------------------------------------------------- /samples/p4paxos/includes/parser.p4: -------------------------------------------------------------------------------- 1 | #ifndef _PARSER_P4_ 2 | #define _PARSER_P4_ 3 | 4 | // Parser for ethernet, ipv4, and udp headers 5 | 6 | parser start { 7 | return parse_ethernet; 8 | } 9 | 10 | #define ETHERTYPE_IPV4 0x0800 11 | #define UDP_PROTOCOL 0x11 12 | #define PAXOS_PROTOCOL 0x8888 13 | 14 | parser parse_ethernet { 15 | extract(ethernet); 16 | return select(latest.etherType) { 17 | ETHERTYPE_IPV4 : parse_ipv4; 18 | default : ingress; 19 | } 20 | } 21 | 22 | parser parse_ipv4 { 23 | extract(ipv4); 24 | return select(latest.protocol) { 25 | UDP_PROTOCOL : parse_udp; 26 | default : ingress; 27 | } 28 | } 29 | 30 | parser parse_udp { 31 | extract(udp); 32 | return select(udp.dstPort) { 33 | PAXOS_PROTOCOL: parse_paxos; 34 | default: ingress; 35 | } 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /samples/p4paxos/includes/paxos_headers.p4: -------------------------------------------------------------------------------- 1 | #ifndef _PAXOS_HEADERS_P4_ 2 | #define _PAXOS_HEADERS_P4_ 3 | 4 | // Headers for Paxos 5 | 6 | #define MSGTYPE_SIZE 8 7 | #define ROUND_SIZE 8 8 | #define INSTANCE_SIZE 16 9 | #define VALUE_SIZE 512 10 | #define DATAPATH_SIZE 64 11 | 12 | #define PAXOS_1A 1 13 | #define PAXOS_1B 2 14 | #define PAXOS_2A 3 15 | #define PAXOS_2B 4 16 | 17 | header_type paxos_t { 18 | fields { 19 | msgtype : MSGTYPE_SIZE; // indicates the message type e.g., 1A, 1B, etc. 20 | instance : INSTANCE_SIZE; // instance number 21 | round : ROUND_SIZE; // round number 22 | vround : ROUND_SIZE; // round in which an acceptor casted a vote 23 | acceptor: DATAPATH_SIZE; // the acceptor id is the datapath (switch) id 24 | value : VALUE_SIZE; // the value the acceptor voted for 25 | } 26 | } 27 | 28 | header paxos_t paxos; 29 | 30 | #endif -------------------------------------------------------------------------------- /samples/p4paxos/includes/paxos_parser.p4: -------------------------------------------------------------------------------- 1 | #ifndef _PAXOS_PARSER_P4_ 2 | #define _PAXOS_PARSER_P4_ 3 | 4 | // Parser for paxos packet headers 5 | 6 | parser parse_paxos { 7 | extract(paxos); 8 | return ingress; 9 | } 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /samples/p4paxos/l2_control.p4: -------------------------------------------------------------------------------- 1 | #include "includes/headers.p4" 2 | #include "includes/parser.p4" 3 | 4 | header_type intrinsic_metadata_t { 5 | fields { 6 | mcast_grp : 4; 7 | egress_rid : 4; 8 | mcast_hash : 16; 9 | lf_field_list: 32; 10 | } 11 | } 12 | 13 | metadata intrinsic_metadata_t intrinsic_metadata; 14 | 15 | action _drop() { 16 | drop(); 17 | } 18 | 19 | action _nop() { 20 | 21 | } 22 | 23 | #define MAC_LEARN_RECEIVER 1024 24 | 25 | field_list mac_learn_digest { 26 | ethernet.srcAddr; 27 | standard_metadata.ingress_port; 28 | } 29 | 30 | action mac_learn() { 31 | generate_digest(MAC_LEARN_RECEIVER, mac_learn_digest); 32 | } 33 | 34 | table smac { 35 | reads { 36 | ethernet.srcAddr : exact; 37 | } 38 | actions {mac_learn; _nop;} 39 | size : 512; 40 | } 41 | 42 | action forward(port) { 43 | modify_field(standard_metadata.egress_spec, port); 44 | } 45 | 46 | action broadcast() { 47 | modify_field(intrinsic_metadata.mcast_grp, 1); 48 | } 49 | 50 | table dmac { 51 | reads { 52 | ethernet.dstAddr : exact; 53 | } 54 | actions { 55 | forward; 56 | broadcast; 57 | } 58 | size : 512; 59 | } 60 | 61 | table mcast_src_pruning { 62 | reads { 63 | standard_metadata.instance_type : exact; 64 | } 65 | actions {_nop; _drop;} 66 | size : 1; 67 | } 68 | 69 | table drop_tbl { 70 | actions { _drop; } 71 | size : 1; 72 | } 73 | 74 | control egress { 75 | if(standard_metadata.ingress_port == standard_metadata.egress_port) { 76 | apply(mcast_src_pruning); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /samples/p4paxos/output/pcapplusplus/paxos_acceptor_paxos.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'paxos' 2 | 3 | #ifndef P4_PAXOS_LAYER 4 | #define P4_PAXOS_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct paxoshdr{ 20 | uint8_t msgtype; 21 | uint16_t instance; 22 | uint8_t round; 23 | uint8_t vround; 24 | uint64_t acceptor; 25 | -- fill blank here 512 value; 26 | }; 27 | 28 | #pragma pack(pop) 29 | class PaxosLayer: public Layer{ 30 | public: 31 | PaxosLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_PAXOS;} 32 | PaxosLayer(){ 33 | m_DataLen = sizeof(paxoshdr); 34 | m_Data = new uint8_t[m_DataLen]; 35 | memset(m_Data, 0, m_DataLen); 36 | m_Protocol = P4_PAXOS; 37 | } 38 | 39 | // Getters and Setters for fields 40 | uint8_t getMsgtype(); 41 | void setMsgtype(uint8_t value); 42 | uint16_t getInstance(); 43 | void setInstance(uint16_t value); 44 | uint8_t getRound(); 45 | void setRound(uint8_t value); 46 | uint8_t getVround(); 47 | void setVround(uint8_t value); 48 | uint64_t getAcceptor(); 49 | void setAcceptor(uint64_t value); 50 | None getValue(); 51 | void setValue(None value); 52 | 53 | inline paxoshdr* getPaxosHeader() { return (paxoshdr*)m_Data; } 54 | 55 | void parseNextLayer(); 56 | 57 | inline size_t getHeaderLen() { return sizeof(paxoshdr); } 58 | 59 | void computeCalculateFields() {} 60 | 61 | std::string toString(); 62 | 63 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 64 | 65 | }; 66 | } 67 | #endif -------------------------------------------------------------------------------- /samples/p4paxos/output/scapy/paxos_acceptor.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class Paxos(Packet): 5 | name = 'paxos' 6 | fields_desc = [ 7 | XByteField('msgtype', 0), 8 | XShortField('instance', 0), 9 | XByteField('round', 0), 10 | XByteField('vround', 0), 11 | XLongField('acceptor', 0), 12 | XBitField('value', 0, 512), 13 | ] 14 | 15 | ## remaining bindings 16 | bind_layers(Ether, IP, type=0x0800) 17 | bind_layers(IP, UDP, proto=0x11) 18 | bind_layers(UDP, Paxos, dport=0x8888) 19 | 20 | ##packet_list 21 | 22 | #No possible packets which can be parsed to the final state -------------------------------------------------------------------------------- /samples/p4paxos/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/p4paxos/output/wireshark/paxos_acceptor_1_ipv4.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/p4paxos/output/wireshark/paxos_acceptor_2_udp.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/p4paxos/output/wireshark/paxos_acceptor_3_paxos.lua') 4 | -------------------------------------------------------------------------------- /samples/p4paxos/output/wireshark/paxos_acceptor_2_udp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_udp = Proto('p4_udp','P4_UDPProtocol') 3 | 4 | -- protocol fields 5 | local p4_udp_srcPort = ProtoField.string('p4_udp.srcPort','srcPort') 6 | local p4_udp_dstPort = ProtoField.string('p4_udp.dstPort','dstPort') 7 | local p4_udp_length_ = ProtoField.string('p4_udp.length_','length_') 8 | local p4_udp_checksum = ProtoField.string('p4_udp.checksum','checksum') 9 | p4_udp.fields = {p4_udp_srcPort, p4_udp_dstPort, p4_udp_length_, p4_udp_checksum} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_udp.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_UDP' 15 | local subtree = tree:add(p4_udp,buffer(),'P4_UDP Protocol Data') 16 | subtree:add(p4_udp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_udp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_udp_length_,tostring(buffer(4,2):bitfield(0,16))) 19 | subtree:add(p4_udp_checksum,tostring(buffer(6,2):bitfield(0,16))) 20 | local mydissectortable = DissectorTable.get('p4_udp.dstPort') 21 | mydissectortable:try(buffer(2,2):bitfield(0,16), buffer:range(8):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_udp.dstPort','P4_UDP.DSTPORT',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('p4_ipv4.protocol') 32 | my_table:add(0x11,p4_udp) 33 | -------------------------------------------------------------------------------- /samples/p4paxos/output/wireshark/paxos_acceptor_3_paxos.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_paxos = Proto('p4_paxos','P4_PAXOSProtocol') 3 | 4 | -- protocol fields 5 | local p4_paxos_msgtype = ProtoField.string('p4_paxos.msgtype','msgtype') 6 | local p4_paxos_instance = ProtoField.string('p4_paxos.instance','instance') 7 | local p4_paxos_round = ProtoField.string('p4_paxos.round','round') 8 | local p4_paxos_vround = ProtoField.string('p4_paxos.vround','vround') 9 | local p4_paxos_acceptor = ProtoField.string('p4_paxos.acceptor','acceptor') 10 | local p4_paxos_value = ProtoField.string('p4_paxos.value','value') 11 | p4_paxos.fields = {p4_paxos_msgtype, p4_paxos_instance, p4_paxos_round, p4_paxos_vround, p4_paxos_acceptor, p4_paxos_value} 12 | 13 | 14 | -- protocol dissector function 15 | function p4_paxos.dissector(buffer,pinfo,tree) 16 | pinfo.cols.protocol = 'P4_PAXOS' 17 | local subtree = tree:add(p4_paxos,buffer(),'P4_PAXOS Protocol Data') 18 | subtree:add(p4_paxos_msgtype,tostring(buffer(0,1):bitfield(0,8))) 19 | subtree:add(p4_paxos_instance,tostring(buffer(1,2):bitfield(0,16))) 20 | subtree:add(p4_paxos_round,tostring(buffer(3,1):bitfield(0,8))) 21 | subtree:add(p4_paxos_vround,tostring(buffer(4,1):bitfield(0,8))) 22 | subtree:add(p4_paxos_acceptor,tostring(buffer(5,8):bitfield(0,64))) 23 | subtree:add(p4_paxos_value,tostring(buffer(13,64):bitfield(0,512))) 24 | 25 | end 26 | 27 | print( (require 'debug').getinfo(1).source ) 28 | 29 | -- creation of table for next layer(if required) 30 | 31 | -- No table required 32 | 33 | -- protocol registration 34 | my_table = DissectorTable.get('p4_udp.dstPort') 35 | my_table:add(0x8888,p4_paxos) 36 | -------------------------------------------------------------------------------- /samples/p4paxos/paxos_coordinator.p4: -------------------------------------------------------------------------------- 1 | #include "includes/paxos_headers.p4" 2 | #include "includes/paxos_parser.p4" 3 | #include "l2_control.p4" 4 | 5 | 6 | register instance_register { 7 | width : INSTANCE_SIZE; 8 | instance_count : 1; 9 | } 10 | 11 | // This action changes a request message to a 2A message and writes the current instance number to the packet header. 12 | // Then, it increments the current instance number by 1 and stores the result in a register. 13 | action handle_request() { 14 | modify_field(paxos.msgtype, PAXOS_2A); 15 | modify_field(paxos.round, 0); 16 | register_read(paxos.instance, instance_register, 0); 17 | add_to_field(paxos.instance, 1); 18 | register_write(instance_register, 0, paxos.instance); 19 | } 20 | 21 | table tbl_sequence { 22 | reads { paxos.msgtype : exact; } 23 | actions { handle_request; _nop; } 24 | size : 1; 25 | } 26 | 27 | control ingress { 28 | apply(smac); /* MAC learning from l2_control.p4... */ 29 | apply(dmac); /* ... not doing Paxos logic */ 30 | 31 | if (valid(paxos)) { /* check if we have a paxos packet */ 32 | apply(tbl_sequence); /* increase paxos instance number */ 33 | } 34 | } -------------------------------------------------------------------------------- /samples/qmetadata/includes/parser.p4: -------------------------------------------------------------------------------- 1 | #define ETHERTYPE_IPV4 0x0800 2 | #define IP_PROTOCOLS_UDP 17 3 | #define QMETA_UDP_DST 7777 4 | #define SNAPSHOT_DEBUG_UDP_DST 8888 5 | 6 | 7 | parser start { 8 | return parse_ethernet; 9 | } 10 | 11 | 12 | 13 | parser parse_ethernet { 14 | extract(ethernet); 15 | return select(latest.etherType) { 16 | ETHERTYPE_IPV4 : parse_ipv4; 17 | default: ingress; 18 | } 19 | } 20 | 21 | 22 | parser parse_ipv4 { 23 | extract(ipv4); 24 | return select(latest.protocol){ 25 | IP_PROTOCOLS_UDP : parse_udp; 26 | default : ingress; 27 | } 28 | } 29 | 30 | parser parse_udp{ 31 | extract(udp); 32 | return select(latest.dstPort){ 33 | QMETA_UDP_DST : parse_q_meta; 34 | SNAPSHOT_DEBUG_UDP_DST: parse_snapshot_debug; 35 | default : ingress; 36 | } 37 | } 38 | 39 | parser parse_q_meta{ 40 | extract(q_meta); 41 | return ingress; 42 | } 43 | 44 | 45 | parser parse_snapshot_debug{ 46 | extract(snapshot); 47 | return ingress; 48 | } 49 | -------------------------------------------------------------------------------- /samples/qmetadata/output/pcapplusplus/qmetadata_q_meta.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'q_meta' 2 | 3 | #ifndef P4_Q_META_LAYER 4 | #define P4_Q_META_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct q_metahdr{ 20 | uint16_t flow_id; 21 | uint64_t ingress_global_tstamp; 22 | uint64_t egress_global_tstamp; 23 | uint16_t markbit; 24 | uint24_t enq_qdepth; 25 | uint24_t deq_qdepth; 26 | }; 27 | 28 | #pragma pack(pop) 29 | class Q_metaLayer: public Layer{ 30 | public: 31 | Q_metaLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_Q_META;} 32 | Q_metaLayer(){ 33 | m_DataLen = sizeof(q_metahdr); 34 | m_Data = new uint8_t[m_DataLen]; 35 | memset(m_Data, 0, m_DataLen); 36 | m_Protocol = P4_Q_META; 37 | } 38 | 39 | // Getters and Setters for fields 40 | uint16_t getFlow_id(); 41 | void setFlow_id(uint16_t value); 42 | uint64_t getIngress_global_tstamp(); 43 | void setIngress_global_tstamp(uint64_t value); 44 | uint64_t getEgress_global_tstamp(); 45 | void setEgress_global_tstamp(uint64_t value); 46 | uint16_t getMarkbit(); 47 | void setMarkbit(uint16_t value); 48 | uint32_t getEnq_qdepth(); 49 | void setEnq_qdepth(uint32_t value); 50 | uint32_t getDeq_qdepth(); 51 | void setDeq_qdepth(uint32_t value); 52 | 53 | inline q_metahdr* getQ_metaHeader() { return (q_metahdr*)m_Data; } 54 | 55 | void parseNextLayer(); 56 | 57 | inline size_t getHeaderLen() { return sizeof(q_metahdr); } 58 | 59 | void computeCalculateFields() {} 60 | 61 | std::string toString(); 62 | 63 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 64 | 65 | }; 66 | } 67 | #endif -------------------------------------------------------------------------------- /samples/qmetadata/output/scapy/qmetadata.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class Q_meta(Packet): 5 | name = 'q_meta' 6 | fields_desc = [ 7 | XShortField('flow_id', 0), 8 | XShortField('_pad0', 0), 9 | XBitField('ingress_global_tstamp', 0, 48), 10 | XShortField('_pad1', 0), 11 | XBitField('egress_global_tstamp', 0, 48), 12 | XBitField('_pad2', 0, 15), 13 | XBitField('markbit', 0, 1), 14 | XBitField('_pad3', 0, 5), 15 | XBitField('enq_qdepth', 0, 19), 16 | XBitField('_pad4', 0, 5), 17 | XBitField('deq_qdepth', 0, 19), 18 | ] 19 | class Snapshot(Packet): 20 | name = 'snapshot' 21 | fields_desc = [ 22 | XShortField('ingress_global_tstamp_hi_16', 0), 23 | XIntField('ingress_global_tstamp_lo_32', 0), 24 | XIntField('egress_global_tstamp_lo_32', 0), 25 | XIntField('enq_qdepth', 0), 26 | XIntField('deq_qdepth', 0), 27 | XShortField('_pad0', 0), 28 | XBitField('orig_egress_global_tstamp', 0, 48), 29 | XShortField('_pad1', 0), 30 | XBitField('new_egress_global_tstamp', 0, 48), 31 | XIntField('new_enq_tstamp', 0), 32 | ] 33 | #update hdrChecksum over [['ipv4', 'version'], ['ipv4', 'ihl'], ['ipv4', 'diffserv'], ['ipv4', 'totalLen'], ['ipv4', 'identification'], ['ipv4', 'flags'], ['ipv4', 'fragOffset'], ['ipv4', 'ttl'], ['ipv4', 'protocol'], ['ipv4', 'srcAddr'], ['ipv4', 'dstAddr']] using csum16 in post_build method 34 | 35 | 36 | ## remaining bindings 37 | bind_layers(Ether, IP, type=0x0800) 38 | bind_layers(IP, UDP, proto=0x11) 39 | bind_layers(UDP, Q_meta, dport=0x1e61) 40 | bind_layers(UDP, Snapshot, dport=0x22b8) 41 | 42 | ##packet_list 43 | 44 | #No possible packets which can be parsed to the final state -------------------------------------------------------------------------------- /samples/qmetadata/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/qmetadata/output/wireshark/qmetadata_1_ipv4.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/qmetadata/output/wireshark/qmetadata_2_udp.lua') 3 | dofile('/home/raj/workspace/p4-traffictool/samples/qmetadata/output/wireshark/qmetadata_3_q_meta.lua') 4 | dofile('/home/raj/workspace/p4-traffictool/samples/qmetadata/output/wireshark/qmetadata_4_snapshot.lua') 5 | -------------------------------------------------------------------------------- /samples/qmetadata/output/wireshark/qmetadata_2_udp.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_udp = Proto('p4_udp','P4_UDPProtocol') 3 | 4 | -- protocol fields 5 | local p4_udp_srcPort = ProtoField.string('p4_udp.srcPort','srcPort') 6 | local p4_udp_dstPort = ProtoField.string('p4_udp.dstPort','dstPort') 7 | local p4_udp_hdr_length = ProtoField.string('p4_udp.hdr_length','hdr_length') 8 | local p4_udp_checksum = ProtoField.string('p4_udp.checksum','checksum') 9 | p4_udp.fields = {p4_udp_srcPort, p4_udp_dstPort, p4_udp_hdr_length, p4_udp_checksum} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_udp.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_UDP' 15 | local subtree = tree:add(p4_udp,buffer(),'P4_UDP Protocol Data') 16 | subtree:add(p4_udp_srcPort,tostring(buffer(0,2):bitfield(0,16))) 17 | subtree:add(p4_udp_dstPort,tostring(buffer(2,2):bitfield(0,16))) 18 | subtree:add(p4_udp_hdr_length,tostring(buffer(4,2):bitfield(0,16))) 19 | subtree:add(p4_udp_checksum,tostring(buffer(6,2):bitfield(0,16))) 20 | local mydissectortable = DissectorTable.get('p4_udp.dstPort') 21 | mydissectortable:try(buffer(2,2):bitfield(0,16), buffer:range(8):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_udp.dstPort','P4_UDP.DSTPORT',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('p4_ipv4.protocol') 32 | my_table:add(0x11,p4_udp) 33 | -------------------------------------------------------------------------------- /samples/qmetadata/qmetadata.p4: -------------------------------------------------------------------------------- 1 | #include "includes/headers.p4" 2 | #include "includes/parser.p4" 3 | 4 | /****** START: Common actions ******/ 5 | 6 | action nop() { 7 | } 8 | 9 | 10 | /****** END: Common actions ******/ 11 | 12 | 13 | /****** START: Tables and actions ******/ 14 | 15 | table do_nothing{ 16 | actions { 17 | nop; 18 | } 19 | default_action: nop; 20 | size: 1; 21 | } 22 | 23 | 24 | /****** END: Tables and actions ******/ 25 | 26 | 27 | 28 | 29 | /************ INGRESS PROCESSING PIPELINE ************/ 30 | 31 | control ingress { 32 | apply(do_nothing); 33 | } 34 | 35 | 36 | 37 | /************ EGRESS PROCESSING PIPELINE ************/ 38 | 39 | control egress { 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /samples/sources.txt: -------------------------------------------------------------------------------- 1 | P4D2 2017 Spring Exercises 2 | https://github.com/BEsdn/P4-tutorials/tree/master/P4D2_2017_Spring/exercises 3 | --------------------------------------------------- 4 | mri 5 | --------------------------------------------------- 6 | 7 | 8 | 9 | 10 | P4D2 2018 Easy Exercises 11 | https://github.com/BEsdn/P4-tutorials/tree/master/P4D2_2018_East/exercises 12 | --------------------------------------------------- 13 | basic_tunnel 14 | src_routing 15 | --------------------------------------------------- 16 | 17 | 18 | 19 | 20 | https://github.com/BEsdn/P4-tutorials/tree/efe6a5586deb9ff61380f466ff7f94498cd24ea8/SIGCOMM_2017/exercises/hula 21 | --------------------------------------------------- 22 | hula 23 | 24 | 25 | 26 | qmetadata is a self-contributed sample 27 | 28 | 29 | -------------------------------------------------------------------------------- /samples/src_routing/output/pcapplusplus/src_routing_srcRoutes.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_MODULE PacketLogModuleSrcroutesLayer 2 | 3 | #include "src_routing_srcRoutes.h" 4 | #include "src_routing_ipv4.h" 5 | #include "src_routing_srcRoutes.h" 6 | #include "PayloadLayer.h" 7 | #include "IpUtils.h" 8 | #include "Logger.h" 9 | #include 10 | #include 11 | #include 12 | 13 | namespace pcpp{ 14 | uint8_t SrcroutesLayer::getBos(){ 15 | uint8_t bos; 16 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 17 | bos = (hdrdata->bos); 18 | return bos; 19 | } 20 | 21 | void SrcroutesLayer::setBos(uint8_t value){ 22 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 23 | hdrdata->bos = (value); 24 | } 25 | uint16_t SrcroutesLayer::getPort(){ 26 | uint16_t port; 27 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 28 | port = htons(hdrdata->port); 29 | return port; 30 | } 31 | 32 | void SrcroutesLayer::setPort(uint16_t value){ 33 | srcrouteshdr* hdrdata = (srcrouteshdr*)m_Data; 34 | hdrdata->port = htons(value); 35 | } 36 | void SrcroutesLayer::parseNextLayer(){ 37 | if (m_DataLen <= sizeof(srcrouteshdr)) 38 | return; 39 | 40 | uint8_t bos = SrcroutesLayer::getBos(); 41 | if (bos == 0x01) 42 | m_NextLayer = new Ipv4Layer(m_Data+sizeof(srcrouteshdr), m_DataLen - sizeof(srcrouteshdr), this, m_Packet); 43 | else if (bos == 0xfa) 44 | m_NextLayer = new SrcroutesLayer(m_Data+sizeof(srcrouteshdr), m_DataLen - sizeof(srcrouteshdr), this, m_Packet); 45 | m_NextLayer = new PayloadLayer(m_Data + sizeof(srcrouteshdr), m_DataLen - sizeof(srcrouteshdr), this, m_Packet); 46 | } 47 | 48 | std::string SrcroutesLayer::toString(){ return ""; } 49 | 50 | } -------------------------------------------------------------------------------- /samples/src_routing/output/pcapplusplus/src_routing_srcRoutes.h: -------------------------------------------------------------------------------- 1 | //Template for addition of new protocol 'srcRoutes' 2 | 3 | #ifndef P4_SRCROUTES_LAYER 4 | #define P4_SRCROUTES_LAYER 5 | 6 | #include 7 | #include "Layer.h" 8 | #include "uint24_t.h" 9 | #include "uint40_t.h" 10 | #include "uint48_t.h" 11 | #if defined(WIN32) || defined(WINx64) 12 | #include 13 | #elif LINUX 14 | #include 15 | #endif 16 | 17 | namespace pcpp{ 18 | #pragma pack(push,1) 19 | struct srcrouteshdr{ 20 | uint8_t bos; 21 | uint16_t port; 22 | }; 23 | 24 | #pragma pack(pop) 25 | class SrcroutesLayer: public Layer{ 26 | public: 27 | SrcroutesLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet): Layer(data, dataLen, prevLayer, packet) {m_Protocol = P4_SRCROUTES;} 28 | SrcroutesLayer(){ 29 | m_DataLen = sizeof(srcrouteshdr); 30 | m_Data = new uint8_t[m_DataLen]; 31 | memset(m_Data, 0, m_DataLen); 32 | m_Protocol = P4_SRCROUTES; 33 | } 34 | 35 | // Getters and Setters for fields 36 | uint8_t getBos(); 37 | void setBos(uint8_t value); 38 | uint16_t getPort(); 39 | void setPort(uint16_t value); 40 | 41 | inline srcrouteshdr* getSrcroutesHeader() { return (srcrouteshdr*)m_Data; } 42 | 43 | void parseNextLayer(); 44 | 45 | inline size_t getHeaderLen() { return sizeof(srcrouteshdr); } 46 | 47 | void computeCalculateFields() {} 48 | 49 | std::string toString(); 50 | 51 | OsiModelLayer getOsiModelLayer() { return OsiModelApplicationLayer; } 52 | 53 | }; 54 | } 55 | #endif -------------------------------------------------------------------------------- /samples/src_routing/output/scapy/src_routing.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | 3 | ##class definitions 4 | class SrcRoutes(Packet): 5 | name = 'srcRoutes' 6 | fields_desc = [ 7 | XBitField('_pad0', 0, 7), 8 | XBitField('bos', 0, 1), 9 | XBitField('_pad1', 0, 1), 10 | XBitField('port', 0, 15), 11 | ] 12 | 13 | def guess_payload_class(self, payload): 14 | if (self.bos == 0x01): 15 | return Ip 16 | elif (self.bos == 0xfa): 17 | return Srcroutes 18 | else: 19 | return Packet.guess_payload_class(self, payload) 20 | 21 | 22 | ## remaining bindings 23 | bind_layers(Ether, SrcRoutes, type=0x1234) 24 | 25 | ##packet_list 26 | possible_packets_ = [ 27 | (Ether()), 28 | (Ether()/SrcRoutes()/IP()), 29 | (Ether()/SrcRoutes()/SrcRoutes()/IP()), 30 | (Ether()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 31 | (Ether()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 32 | (Ether()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 33 | (Ether()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 34 | (Ether()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()), 35 | (Ether()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/SrcRoutes()/IP()) 36 | ] 37 | -------------------------------------------------------------------------------- /samples/src_routing/output/wireshark/init.lua: -------------------------------------------------------------------------------- 1 | dofile('/home/raj/workspace/p4-traffictool/samples/src_routing/output/wireshark/src_routing_1_srcRoutes.lua') 2 | dofile('/home/raj/workspace/p4-traffictool/samples/src_routing/output/wireshark/src_routing_2_ipv4.lua') 3 | -------------------------------------------------------------------------------- /samples/src_routing/output/wireshark/src_routing_1_srcRoutes.lua: -------------------------------------------------------------------------------- 1 | -- protocol naming 2 | p4_srcroutes = Proto('p4_srcroutes','P4_SRCROUTESProtocol') 3 | 4 | -- protocol fields 5 | local p4_srcroutes__pad0 = ProtoField.string('p4_srcroutes._pad0','_pad0') 6 | local p4_srcroutes_bos = ProtoField.string('p4_srcroutes.bos','bos') 7 | local p4_srcroutes__pad1 = ProtoField.string('p4_srcroutes._pad1','_pad1') 8 | local p4_srcroutes_port = ProtoField.string('p4_srcroutes.port','port') 9 | p4_srcroutes.fields = {p4_srcroutes__pad0, p4_srcroutes_bos, p4_srcroutes__pad1, p4_srcroutes_port} 10 | 11 | 12 | -- protocol dissector function 13 | function p4_srcroutes.dissector(buffer,pinfo,tree) 14 | pinfo.cols.protocol = 'P4_SRCROUTES' 15 | local subtree = tree:add(p4_srcroutes,buffer(),'P4_SRCROUTES Protocol Data') 16 | subtree:add(p4_srcroutes__pad0,tostring(buffer(0,1):bitfield(0,7))) 17 | subtree:add(p4_srcroutes_bos,tostring(buffer(0,1):bitfield(7,1))) 18 | subtree:add(p4_srcroutes__pad1,tostring(buffer(1,1):bitfield(0,1))) 19 | subtree:add(p4_srcroutes_port,tostring(buffer(1,2):bitfield(1,15))) 20 | local mydissectortable = DissectorTable.get('p4_srcRoutes.bos') 21 | mydissectortable:try(buffer(0,1):bitfield(7,1), buffer:range(3):tvb(),pinfo,tree) 22 | 23 | end 24 | 25 | print( (require 'debug').getinfo(1).source ) 26 | 27 | -- creation of table for next layer(if required) 28 | local newdissectortable = DissectorTable.new('p4_srcRoutes.bos','P4_SRCROUTES.BOS',ftypes.STRING) 29 | 30 | -- protocol registration 31 | my_table = DissectorTable.get('ethertype') 32 | my_table:add(0x1234,p4_srcroutes) 33 | my_table = DissectorTable.get('p4_srcRoutes.bos') 34 | my_table:add(0x0,p4_srcroutes) 35 | -------------------------------------------------------------------------------- /src/config.py: -------------------------------------------------------------------------------- 1 | # global variables for common header types 2 | ETHER_DETECT = False 3 | IPv4_DETECT = False 4 | IPv6_DETECT = False 5 | TCP_DETECT = False 6 | UDP_DETECT = False 7 | 8 | DEBUG = False 9 | 10 | # Maximum possible headers within a packet, hyperparameter with default value as 10 11 | MAX_PATH_LENGTH = 10 12 | -------------------------------------------------------------------------------- /templates/bitfields_def.lua: -------------------------------------------------------------------------------- 1 | local ffi = require "ffi" 2 | 3 | local ntoh, hton = ntoh, hton 4 | local ntoh16, hton16 = ntoh16, hton16 5 | local bor, band, bnot, rshift, lshift= bit.bor, bit.band, bit.bnot, bit.rshift, bit.lshift 6 | local istype = ffi.istype 7 | 8 | ----- 24 bit address ----- 9 | ffi.cdef[[ 10 | union __attribute__((__packed__)) bitfield_24{ 11 | uint32_t intequiv; 12 | }; 13 | ]] 14 | 15 | local bitfield24 = {} 16 | bitfield24.__index = bitfield24 17 | local bitfield24Type = ffi.typeof("union bitfield_24") 18 | 19 | function bitfield24:get() 20 | return hton(self.intequiv) 21 | end 22 | 23 | function bitfield24:set(addr) 24 | addr = addr or 0 25 | self.intequiv = hton(tonumber(band(addr,0xFFFFFFFFULL))) 26 | 27 | end 28 | 29 | ----- 40 bit address ----- 30 | ffi.cdef[[ 31 | union __attribute__((__packed__)) bitfield_40{ 32 | uint64_t intequiv; 33 | }; 34 | ]] 35 | 36 | local bitfield40 = {} 37 | bitfield40.__index = bitfield40 38 | local bitfield40Type = ffi.typeof("union bitfield_40") 39 | 40 | function bitfield40:get() 41 | return hton64(self.intequiv) 42 | end 43 | 44 | function bitfield40:set(addr) 45 | addr = addr or 0 46 | self.intequiv = hton64(tonumber(band(addr,0xFFFFFFFFFFFFFFFFULL))) 47 | end 48 | 49 | ----- 48 bit address ----- 50 | ffi.cdef[[ 51 | union __attribute__((__packed__)) bitfield_48{ 52 | uint32_t intequiv; 53 | }; 54 | ]] 55 | 56 | local bitfield48 = {} 57 | bitfield48.__index = bitfield48 58 | local bitfield48Type = ffi.typeof("union bitfield_48") 59 | 60 | function bitfield48:get() 61 | return hton64(self.intequiv) 62 | end 63 | 64 | function bitfield48:set(addr) 65 | addr = addr or 0 66 | self.intequiv = hton64(tonumber(band(addr,0xFFFFFFFFFFFFFFFFULL))) 67 | end 68 | 69 | ffi.metatype('union bitfield_24',bitfield24) 70 | ffi.metatype('union bitfield_40',bitfield40) 71 | ffi.metatype('union bitfield_48',bitfield48) 72 | -------------------------------------------------------------------------------- /templates/templateMoonGen.lua: -------------------------------------------------------------------------------- 1 | --[[ Necessary changes to other files: 2 | -- - packet.lua: if the header has a length member, adapt packetSetLength; 3 | -- if the packet has a checksum, adapt createStack (loop at end of function) and packetCalculateChecksums 4 | -- - proto/proto.lua: add PROTO.lua to the list so it gets loaded 5 | --]] 6 | 7 | local ffi = require "ffi" 8 | local dpdkc = require "dpdkc" 9 | 10 | require "bitfields_def" 11 | require "utils" 12 | require "proto.template" 13 | local initHeader = initHeader 14 | 15 | 16 | local ntoh, hton = ntoh, hton 17 | local ntoh16, hton16 = ntoh16, hton16 18 | local bor, band, bnot, rshift, lshift= bit.bor, bit.band, bit.bnot, bit.rshift, bit.lshift 19 | local istype = ffi.istype 20 | local format = string.format 21 | 22 | function hton64(int) 23 | int = int or 0 24 | endianness = string.dump(function() end):byte(7) 25 | if endianness==0 then 26 | return int 27 | end 28 | low_int = lshift(hton(band(int,0xFFFFFFFFULL)),32) 29 | high_int = rshift(hton(band(int,0xFFFFFFFF00000000ULL)),32) 30 | endianness = string.dump(function() end):byte(7) 31 | return (high_int+low_int) 32 | end 33 | 34 | 35 | local ntoh64, hton64 = ntoh64, hton64 36 | -------------------------------------------------------------------------------- /templates/uint24_t.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef UNIT24_T_H 3 | #define UNIT24_T_H 4 | 5 | // uint24_t: type as a byte array (or unsigned char array) 6 | typedef unsigned char uint24_t[3]; 7 | 8 | // UINT24_MAX_VALUE: the maximum value of 'uint24_t'. (2^24)-1 = 16777215 9 | #define UINT24_MAX_VALUE ((1 << 24)-1) 10 | 11 | // UINT24_SET: assign value to 'uint24_t' 12 | #define UINT24_SET(uint24, value) \ 13 | uint24[0] = (unsigned char)(value); \ 14 | uint24[1] = (unsigned char)((value) >> 8); \ 15 | uint24[2] = (unsigned char)((value) >> 16); 16 | 17 | // copies value of one uint24 to other 18 | #define UINT24_COPY(uint24, value) \ 19 | uint24[0] = value[0]; \ 20 | uint24[1] = value[1]; \ 21 | uint24[2] = value[2]; 22 | 23 | // UINT24_GET: obtain value of 'uint24_t' 24 | #define UINT24_GET(uint24) \ 25 | (uint24[0]) + \ 26 | (uint24[1] << 8) + \ 27 | (uint24[2] << 16); 28 | 29 | // UINT24_PRINT: print 'uint24_t' as 3 bytes 30 | #define UINT24_PRINT(uint24) \ 31 | printf("%hhu %hhu %hhu \n", uint24[2], uint24[1], uint24[0]); 32 | 33 | 34 | #if (BYTE_ORDER==LITTLE_ENDIAN) 35 | #define UINT24_HTON(a,b) \ 36 | a[0]=b[2]; \ 37 | a[1]=b[1]; \ 38 | a[2]=b[0]; 39 | #else 40 | #define UINT24_HTON(a,b) UINT24_COPY(a,b) 41 | #endif 42 | 43 | #define UINT24_NTOH(a,b) UINT24_HTON(a,b) 44 | 45 | #endif -------------------------------------------------------------------------------- /templates/uint40_t.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIT40_T_H 2 | #define UNIT40_T_H 3 | 4 | // uint40_t: type as a byte array (or unsigned char array) 5 | typedef unsigned char uint40_t[5]; 6 | 7 | // UINT40_MAX_VALUE: the maximum value of 'uint40_t'. (2^40)-1 = 16777215 8 | #define UINT40_MAX_VALUE ((1 << 40)-1) 9 | 10 | // UINT40_SET: assign value to 'uint40_t' 11 | #define UINT40_SET(uint40, value) \ 12 | uint40[0] = (unsigned char)(value); \ 13 | uint40[1] = (unsigned char)((value) >> 8); \ 14 | uint40[2] = (unsigned char)((value) >> 16); \ 15 | uint40[3] = (unsigned char)((value) >> 24); \ 16 | uint40[4] = (unsigned char)((value) >> 32); 17 | 18 | // copies value of one UINT40 to other 19 | #define UINT40_COPY(uint40, value) \ 20 | uint40[0] = value[0]; \ 21 | uint40[1] = value[1]; \ 22 | uint40[2] = value[2]; \ 23 | uint40[3] = value[3]; \ 24 | uint40[4] = value[4]; 25 | 26 | // UINT40_GET: obtain value of 'uint40_t' 27 | #define UINT40_GET(uint40) \ 28 | (uint40[0]) + \ 29 | (uint40[1] << 8) + \ 30 | (uint40[2] << 16)+ \ 31 | (uint40[3] << 24)+ \ 32 | (uint40[4] << 32); 33 | 34 | 35 | // UINT40_PRINT: print 'uint40_t' as 3 bytes 36 | #define UINT40_PRINT(uint40) \ 37 | printf("%hhu %hhu %hhu %hhu %hhu \n", uint40[4], uint40[3],uint40[2], uint40[1], uint40[0]); 38 | 39 | 40 | #if (BYTE_ORDER==LITTLE_ENDIAN) 41 | #define UINT40_HTON(a,b) \ 42 | a[0]=b[4]; \ 43 | a[1]=b[3]; \ 44 | a[2]=b[2]; \ 45 | a[3]=b[1]; \ 46 | a[4]=b[0]; 47 | #else 48 | #define UINT40_HTON(a,b) UINT40_COPY(a,b) 49 | #endif 50 | 51 | #define UINT40_NTOH(a,b) UINT40_HTON(a,b) 52 | 53 | #endif -------------------------------------------------------------------------------- /templates/uint48_t.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIT48_T_H 2 | #define UNIT48_T_H 3 | 4 | // uint48_t: type as a byte array (or unsigned char array) 5 | typedef unsigned char uint48_t[6]; 6 | 7 | // UINT48_MAX_VALUE: the maximum value of 'uint48_t'. (2^48)-1 = 16777215 8 | #define UINT48_MAX_VALUE ((1 << 48)-1) 9 | 10 | // UINT48_SET: assign value to 'uint48_t' 11 | #define UINT48_SET(uint48, value) \ 12 | uint48[0] = (unsigned char)(value); \ 13 | uint48[1] = (unsigned char)((value) >> 8); \ 14 | uint48[2] = (unsigned char)((value) >> 16); \ 15 | uint48[3] = (unsigned char)((value) >> 24); \ 16 | uint48[4] = (unsigned char)((value) >> 32); \ 17 | uint48[5] = (unsigned char)((value) >> 40); 18 | 19 | // copies value of one UINT48 to other 20 | #define UINT48_COPY(uint48, value) \ 21 | uint48[0] = value[0]; \ 22 | uint48[1] = value[1]; \ 23 | uint48[2] = value[2]; \ 24 | uint48[3] = value[3]; \ 25 | uint48[4] = value[4]; \ 26 | uint48[5] = value[5]; 27 | 28 | 29 | // UINT48_GET: obtain value of 'uint48_t' 30 | #define UINT48_GET(uint48) \ 31 | (uint48[0]) + \ 32 | (uint48[1] << 8) + \ 33 | (uint48[2] << 16)+ \ 34 | (uint48[3] << 24)+ \ 35 | (uint48[4] << 32)+ \ 36 | (uint48[5] << 40); 37 | 38 | 39 | 40 | // UINT48_PRINT: print 'uint48_t' as 3 bytes 41 | #define UINT48_PRINT(uint48) \ 42 | printf("%hhu %hhu %hhu %hhu %hhu %hhu \n", uint48[5] , uint48[4], uint48[3],uint48[2], uint48[1], uint48[0]); 43 | 44 | 45 | #if (BYTE_ORDER==LITTLE_ENDIAN) 46 | #define UINT48_HTON(a,b) \ 47 | a[0]=b[5]; \ 48 | a[1]=b[4]; \ 49 | a[2]=b[3]; \ 50 | a[3]=b[2]; \ 51 | a[4]=b[1]; \ 52 | a[5]=b[0]; 53 | #else 54 | #define UINT48_HTON(a,b) UINT48_COPY(a,b) 55 | #endif 56 | 57 | #define UINT48_NTOH(a,b) UINT48_HTON(a,b) 58 | 59 | #endif -------------------------------------------------------------------------------- /tests/runsamples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf ../samples/basic_postcards/output 3 | rm -rf ../samples/basic_tunnel/output 4 | rm -rf ../samples/hula/output 5 | rm -rf ../samples/linear_road/output 6 | rm -rf ../samples/mri/output 7 | rm -rf ../samples/netcache/output 8 | rm -rf ../samples/netchain/output 9 | rm -rf ../samples/p4paxos/output 10 | rm -rf ../samples/qmetadata/output 11 | rm -rf ../samples/src_routing/output 12 | 13 | # for running in debug mode 14 | yes y|../p4-traffictool -json ../samples/basic_postcards/basic_postcards.json --std p4-16 -o ../samples/basic_postcards/output --scapy --wireshark --moongen --pcpp --debug 15 | yes y|../p4-traffictool -json ../samples/basic_tunnel/basic_tunnel.json --std p4-16 -o ../samples/basic_tunnel/output --scapy --wireshark --moongen --pcpp --debug 16 | yes y|../p4-traffictool -json ../samples/hula/hula.json --std p4-16 -o ../samples/hula/output --scapy --wireshark --moongen --pcpp --debug 17 | yes y|../p4-traffictool -json ../samples/linear_road/linear_road.json --std p4-14 -o ../samples/linear_road/output --scapy --wireshark --moongen --pcpp --debug 18 | yes y|../p4-traffictool -json ../samples/mri/mri.json --std p4-16 -o ../samples/mri/output --scapy --wireshark --moongen --pcpp --debug 19 | yes y|../p4-traffictool -json ../samples/netchain/netchain.json --std p4-16 -o ../samples/netchain/output --scapy --wireshark --moongen --pcpp --debug 20 | yes y|../p4-traffictool -json ../samples/netcache/netcache.json --std p4-16 -o ../samples/netcache/output --scapy --wireshark --moongen --pcpp --debug 21 | yes y|../p4-traffictool -json ../samples/p4paxos/paxos_acceptor.json --std p4-14 -o ../samples/p4paxos/output --scapy --wireshark --moongen --pcpp --debug 22 | yes y|../p4-traffictool -json ../samples/src_routing/src_routing.json --std p4-16 -o ../samples/src_routing/output --scapy --wireshark --moongen --pcpp --debug 23 | yes y|../p4-traffictool -json ../samples/qmetadata/qmetadata.json --std p4-16 -o ../samples/qmetadata/output --scapy --wireshark --moongen --pcpp --debug 24 | -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo rm /usr/bin/p4-traffictool 4 | sudo rm -rf /usr/share/p4-traffictool 5 | 6 | echo "You can remove python3-tabulate and p4c if they are not required anymore" --------------------------------------------------------------------------------