ROFL-pipeline  v0.6.0dev
packet_matches.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef __PACKET_MATCHES_H__
6 #define __PACKET_MATCHES_H__
7 
8 #include <inttypes.h>
9 #include <string.h>
10 #include "rofl.h"
11 #include "ternary_fields.h"
12 #include "../openflow/openflow1x/pipeline/of1x_utils.h"
13 
26 struct datapacket;
27 
28 /*
29 * Packet matching values
30 */
31 typedef struct packet_matches{
32 
33  //Packet size
34  uint32_t __pkt_size_bytes; /* Packet size in bytes */
35 
36  //Ports
37  uint32_t __port_in; /* Switch input port. */
38  uint32_t __phy_port_in; /* Switch physical input port. */
39 
40  //Associated metadata
41  uint64_t __metadata; /* Metadata passed between tables. */
42 
43  //802
44  uint64_t __eth_dst; /* Ethernet destination address. */
45  uint64_t __eth_src; /* Ethernet source address. */
46  uint16_t __eth_type; /* Ethernet frame type (WARNING: inner payload). */
47 
48  //802.1q VLAN outermost tag
49  bool __has_vlan; /* VLAN flag */
50  uint16_t __vlan_vid; /* VLAN id. */
51  uint8_t __vlan_pcp; /* VLAN PCP. */
52 
53  //ARP
54  uint16_t __arp_opcode; /* ARP opcode */
55  uint64_t __arp_sha; /* ARP source hardware address */
56  uint32_t __arp_spa; /* ARP source protocol address */
57  uint64_t __arp_tha; /* ARP target hardware address */
58  uint32_t __arp_tpa; /* ARP target protocol address */
59 
60  //IP
61  uint8_t __ip_proto; /* IP protocol. */
62  uint8_t __ip_dscp; /* IP DSCP (6 bits in ToS field). */
63  uint8_t __ip_ecn; /* IP ECN (2 bits in ToS field). */
64 
65  //IPv4
66  uint32_t __ipv4_src; /* IPv4 source address. */
67  uint32_t __ipv4_dst; /* IPv4 destination address. */
68 
69  //TCP
70  uint16_t __tcp_src; /* TCP source port. */
71  uint16_t __tcp_dst; /* TCP destination port. */
72 
73  //UDP
74  uint16_t __udp_src; /* UDP source port. */
75  uint16_t __udp_dst; /* UDP destination port. */
76 
77  //SCTP
78  uint16_t __sctp_src; /* SCTP source port. */
79  uint16_t __sctp_dst; /* SCTP destination port. */
80 
81 
82  //ICMPv4
83  uint8_t __icmpv4_type; /* ICMP type. */
84  uint8_t __icmpv4_code; /* ICMP code. */
85 
86  //MPLS-outermost label
87  uint32_t __mpls_label; /* MPLS label. */
88  uint8_t __mpls_tc; /* MPLS TC. */
89  bool __mpls_bos; /* MPLS BoS. */
90 
91 
92  //IPv6
93  uint128__t __ipv6_src; /* IPv6 source address */
94  uint128__t __ipv6_dst; /* IPv6 source address */
95  uint64_t __ipv6_flabel; /* IPv6 flow label */
96  uint128__t __ipv6_nd_target; /* IPv6 Neighbor discovery protocol target */
97  uint64_t __ipv6_nd_sll; /* IPv6 Neighbor discovery protocol source link level */
98  uint64_t __ipv6_nd_tll; /* IPv6 Neighbor discovery protocol target link level */
99  uint16_t __ipv6_exthdr; /* IPv6 extension pseudo header */
100 
101  //ICMPv6
102  uint8_t __icmpv6_code; /* ICMPv6 type */
103  uint8_t __icmpv6_type; /* ICMPv6 code */
104 
105  //PBB
106  uint32_t __pbb_isid; /* PBB_ISID code */
107 
108  //Tunnel id
109  uint64_t __tunnel_id; /* Tunnel id*/
110 
111  /*
112  * Extensions
113  */
114 
115  //PPPoE related extensions
116  uint8_t __pppoe_code; /* PPPoE code */
117  uint8_t __pppoe_type; /* PPPoE type */
118  uint16_t __pppoe_sid; /* PPPoE session id */
119 
120  //PPP related extensions
121  uint16_t __ppp_proto; /* PPPoE session id */
122 
123  //GTP related extensions
124  uint8_t __gtp_msg_type; /* GTP message type */
125  uint32_t __gtp_teid; /* GTP teid */
126 
127  //CAPWAP related extensions
128  uint8_t __capwap_wbid; /* CAPWAP WBID */
129  uint8_t __capwap_rid; /* CAPWAP RID */
130  uint16_t __capwap_flags; /* CAPWAP FLAGS */
131 
132  //WLAN related extensions
133  uint16_t __wlan_fc; /* WLAN fc */
134  uint8_t __wlan_type; /* WLAN type */
135  uint8_t __wlan_subtype; /* WLAN subtype */
136  uint8_t __wlan_direction; /* WLAN direction */
137  uint64_t __wlan_address_1; /* WLAN address 1 */
138  uint64_t __wlan_address_2; /* WLAN address 2 */
139  uint64_t __wlan_address_3; /* WLAN address 3 */
140 
141  //GRE related extensions
142  uint16_t __gre_version; /* GRE version */
143  uint16_t __gre_prot_type; /* GRE protocol type */
144  uint32_t __gre_key; /* GRE key */
146 
147 
148 //C++ extern C
149 ROFL_BEGIN_DECLS
150 
156 void dump_packet_matches(struct datapacket *const pkt, bool raw_nbo);
157 
162 void fill_packet_matches(struct datapacket *const pkt, packet_matches_t* pkt_matches);
163 
164 
169 static inline
170 uint32_t packet_matches_get_size_bytes(packet_matches_t *const pkt_matches){
171  return pkt_matches->__pkt_size_bytes;
172 };
173 //Phy
178 static inline
180  return pkt_matches->__port_in;
181 };
186 static inline
188  return pkt_matches->__phy_port_in;
189 };
190 
191 
192 //METADATA
197 static inline
199  return pkt_matches->__metadata;
200 };
201 
202 //ETHERNET
207 static inline
209  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__eth_dst));
210 };
215 static inline
217  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__eth_src));
218 };
223 static inline
225  return NTOHB16(pkt_matches->__eth_type);
226 };
227 
228 //8021.q
233 static inline
234 bool packet_matches_has_vlan(packet_matches_t *const pkt_matches){
235  return pkt_matches->__has_vlan;
236 };
241 static inline
243  return NTOHB16(pkt_matches->__vlan_vid);
244 };
245 
250 static inline
252  return OF1X_VLAN_PCP_VALUE(pkt_matches->__vlan_pcp);
253 };
254 
255 //MPLS
260 static inline
262  return OF1X_MPLS_LABEL_VALUE(NTOHB32(pkt_matches->__mpls_label));
263 };
268 static inline
270  return OF1X_MPLS_TC_VALUE(pkt_matches->__mpls_tc);
271 };
276 static inline
278  return pkt_matches->__mpls_bos;
279 };
280 
281 //ARP
286 static inline
288  return NTOHB16(pkt_matches->__arp_opcode);
289 };
294 static inline
296  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__arp_tha));
297 };
302 static inline
304  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__arp_sha));
305 };
310 static inline
312  return NTOHB32(pkt_matches->__arp_tpa);
313 };
318 static inline
320  return NTOHB32(pkt_matches->__arp_spa);
321 };
322 
323 
324 //IP
329 static inline
331  return pkt_matches->__ip_proto;
332 };
337 static inline
339  return pkt_matches->__ip_ecn;
340 };
345 static inline
347  return OF1X_IP_DSCP_VALUE(pkt_matches->__ip_dscp);
348 };
349 
350 //IPv4
355 static inline
357  return NTOHB32(pkt_matches->__ipv4_src);
358 };
363 static inline
365  return NTOHB32(pkt_matches->__ipv4_dst);
366 };
367 
368 //TCP
373 static inline
375  return NTOHB16(pkt_matches->__tcp_src);
376 };
381 static inline
383  return NTOHB16(pkt_matches->__tcp_dst);
384 };
385 
386 //UDP
391 static inline
393  return NTOHB16(pkt_matches->__udp_src);
394 };
399 static inline
401  return NTOHB16(pkt_matches->__udp_dst);
402 };
403 
404 //SCTP
409 static inline
411  return NTOHB16(pkt_matches->__sctp_src);
412 };
417 static inline
419  return NTOHB16(pkt_matches->__sctp_dst);
420 };
421 
422 //ICMPv4
427 static inline
429  return pkt_matches->__icmpv4_type;
430 };
435 static inline
437  return pkt_matches->__icmpv4_code;
438 };
439 
440 //IPv6
445 static inline
447  uint128__t tmp = pkt_matches->__ipv6_src;
448  NTOHB128(tmp);
449  return tmp;
450 };
455 static inline
457  uint128__t tmp = pkt_matches->__ipv6_dst;
458  NTOHB128(tmp);
459  return tmp;
460 };
465 static inline
467  return OF1X_IP6_FLABEL_VALUE(NTOHB64(pkt_matches->__ipv6_flabel));
468 };
473 static inline
475  uint128__t tmp = pkt_matches->__ipv6_nd_target;
476  NTOHB128(tmp);
477  return tmp;
478 };
483 static inline
485  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__ipv6_nd_sll));
486 };
491 static inline
493  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__ipv6_nd_tll));
494 };
499 static inline
501  return NTOHB16(pkt_matches->__ipv6_exthdr); //TODO align?
502 };
503 
504 //ICMPv6
509 static inline
511  return pkt_matches->__icmpv6_type;
512 };
517 static inline
519  return pkt_matches->__icmpv6_code;
520 };
521 
522 /*
523  * @brief Get the packet match PBB_ISD value in HOST BYTE ORDER
524  * @ingroup core_of1x
525  */
526 static inline
527 uint32_t packet_matches_get_pbb_isid_value(packet_matches_t *const pkt_matches){
528  return NTOHB32(pkt_matches->__pbb_isid); //TODO align?
529 };
530 
535 static inline
537  return NTOHB64(pkt_matches->__tunnel_id);
538 };
539 
540 
541 //PPPoE
546 static inline
548  return pkt_matches->__pppoe_code;
549 };
554 static inline
556  return pkt_matches->__pppoe_type;
557 };
562 static inline
564  return NTOHB16(pkt_matches->__pppoe_sid);
565 };
566 
567 //PPP
572 static inline
574  return NTOHB16(pkt_matches->__ppp_proto);
575 };
576 
577 //GTP
582 static inline
584  return pkt_matches->__gtp_msg_type;
585 };
590 static inline
592  return NTOHB32(pkt_matches->__gtp_teid);
593 };
594 
595 //CAPWAP
600 static inline
602  return pkt_matches->__capwap_wbid;
603 };
608 static inline
610  return pkt_matches->__capwap_rid;
611 };
616 static inline
618  return NTOHB16(pkt_matches->__capwap_flags);
619 };
620 
621 //WLAN
626 static inline
628  return NTOHB16(pkt_matches->__wlan_fc);
629 };
634 static inline
636  return pkt_matches->__wlan_type;
637 };
642 static inline
644  return pkt_matches->__wlan_subtype;
645 };
650 static inline
652  return pkt_matches->__wlan_direction;
653 };
658 static inline
660  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__wlan_address_1));
661 };
666 static inline
668  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__wlan_address_2));
669 };
674 static inline
676  return OF1X_MAC_VALUE(NTOHB64(pkt_matches->__wlan_address_3));
677 };
678 
679 //GRE
684 static inline
686  return NTOHB16(pkt_matches->__gre_version);
687 };
692 static inline
694  return NTOHB16(pkt_matches->__gre_prot_type);
695 };
700 static inline
702  return NTOHB32(pkt_matches->__gre_key);
703 };
704 
705 //C++ extern C
706 ROFL_END_DECLS
707 
708 #endif //PACKET_MATCHES
static bool packet_matches_get_mpls_bos_value(packet_matches_t *const pkt_matches)
Get the packet match MPLS_BOS value in HOST BYTE ORDER.
static uint8_t packet_matches_get_vlan_pcp_value(packet_matches_t *const pkt_matches)
Get the packet match VLAN_PCP value in HOST BYTE ORDER.
static uint16_t packet_matches_get_gre_version_value(packet_matches_t *const pkt_matches)
Get the packet match GRE_VERSION value in HOST BYTE ORDER.
static uint16_t packet_matches_get_ipv6_exthdr_value(packet_matches_t *const pkt_matches)
Get the packet match IP6_EXTHDR value in HOST BYTE ORDER.
static uint8_t packet_matches_get_pppoe_type_value(packet_matches_t *const pkt_matches)
Get the packet match PPPOE_TYPE value in HOST BYTE ORDER.
static uint32_t packet_matches_get_port_in_value(packet_matches_t *const pkt_matches)
Get the packet match PORT_IN value in HOST BYTE ORDER.
static uint8_t packet_matches_get_capwap_wbid_value(packet_matches_t *const pkt_matches)
Get the packet match CAPWAP_WBID value in HOST BYTE ORDER.
static uint64_t packet_matches_get_ipv6_nd_sll_value(packet_matches_t *const pkt_matches)
Get the packet match IP6_ND_SLL value in HOST BYTE ORDER.
static uint16_t packet_matches_get_sctp_dst_value(packet_matches_t *const pkt_matches)
Get the packet match SCTP_DST value in HOST BYTE ORDER.
static uint64_t packet_matches_get_arp_sha_value(packet_matches_t *const pkt_matches)
Get the packet match ARP_SHA value in HOST BYTE ORDER.
static uint8_t packet_matches_get_gtp_msg_type_value(packet_matches_t *const pkt_matches)
Get the packet match PPP_PROTO value in HOST BYTE ORDER.
static uint32_t packet_matches_get_phy_port_in_value(packet_matches_t *const pkt_matches)
Get the packet match PHY_PORT_IN value in HOST BYTE ORDER.
static uint16_t packet_matches_get_arp_opcode_value(packet_matches_t *const pkt_matches)
Get the packet match ARP_OPCODE value in HOST BYTE ORDER.
static uint64_t packet_matches_get_tunnel_id_value(packet_matches_t *const pkt_matches)
Get the packet match TUNNEL_ID value in HOST BYTE ORDER.
static uint16_t packet_matches_get_capwap_flags_value(packet_matches_t *const pkt_matches)
Get the packet match CAPWAP_FLAGS value in HOST BYTE ORDER.
static uint128__t packet_matches_get_ipv6_nd_target_value(packet_matches_t *const pkt_matches)
Get the packet match IP6_ND_TARGET value in HOST BYTE ORDER.
static uint16_t packet_matches_get_gre_prot_type_value(packet_matches_t *const pkt_matches)
Get the packet match GRE_PROT_TYPE value in HOST BYTE ORDER.
static uint16_t packet_matches_get_tcp_src_value(packet_matches_t *const pkt_matches)
Get the packet match TCP_SRC value in HOST BYTE ORDER.
static uint64_t packet_matches_get_wlan_address_3_value(packet_matches_t *const pkt_matches)
Get the packet match WLAN_ADDRESS_3 value in HOST BYTE ORDER.
static uint8_t packet_matches_get_wlan_direction_value(packet_matches_t *const pkt_matches)
Get the packet match WLAN_DIRECTION value in HOST BYTE ORDER.
static uint32_t packet_matches_get_size_bytes(packet_matches_t *const pkt_matches)
Get the packet match PACKET_LENGTH value in HOST BYTE ORDER.
static uint32_t packet_matches_get_gre_key_value(packet_matches_t *const pkt_matches)
Get the packet match GRE_KEY value in HOST BYTE ORDER.
static uint128__t packet_matches_get_ipv6_src_value(packet_matches_t *const pkt_matches)
Get the packet match IP6_SRC value in HOST BYTE ORDER.
static uint16_t packet_matches_get_tcp_dst_value(packet_matches_t *const pkt_matches)
Get the packet match TCP_DST value in HOST BYTE ORDER.
static uint16_t packet_matches_get_udp_dst_value(packet_matches_t *const pkt_matches)
Get the packet match UDP_DST value in HOST BYTE ORDER.
static uint32_t packet_matches_get_arp_tpa_value(packet_matches_t *const pkt_matches)
Get the packet match ARP_TPA value in HOST BYTE ORDER.
static uint16_t packet_matches_get_wlan_fc_value(packet_matches_t *const pkt_matches)
Get the packet match WLAN_FC value in HOST BYTE ORDER.
static uint8_t packet_matches_get_wlan_subtype_value(packet_matches_t *const pkt_matches)
Get the packet match WLAN_SUBTYPE value in HOST BYTE ORDER.
static uint8_t packet_matches_get_mpls_tc_value(packet_matches_t *const pkt_matches)
Get the packet match MPLS_TC value in HOST BYTE ORDER.
static uint8_t packet_matches_get_ip_proto_value(packet_matches_t *const pkt_matches)
Get the packet match IP_PROTO value in HOST BYTE ORDER.
static uint64_t packet_matches_get_ipv6_nd_tll_value(packet_matches_t *const pkt_matches)
Get the packet match IP6_ND_TLL value in HOST BYTE ORDER.
static uint16_t packet_matches_get_eth_type_value(packet_matches_t *const pkt_matches)
Get the packet match ETH_TYPE value in HOST BYTE ORDER.
static uint8_t packet_matches_get_wlan_type_value(packet_matches_t *const pkt_matches)
Get the packet match WLAN_TYPE value in HOST BYTE ORDER.
static bool packet_matches_has_vlan(packet_matches_t *const pkt_matches)
Get flag has vlan.
static uint8_t packet_matches_get_icmpv6_type_value(packet_matches_t *const pkt_matches)
Get the packet match ICMPV6_TYPE value in HOST BYTE ORDER.
static uint16_t packet_matches_get_sctp_src_value(packet_matches_t *const pkt_matches)
Get the packet match SCTP_SRC value in HOST BYTE ORDER.
static uint64_t packet_matches_get_ipv6_flabel_value(packet_matches_t *const pkt_matches)
Get the packet match IP6_FLABEL value in HOST BYTE ORDER.
static uint8_t packet_matches_get_icmpv6_code_value(packet_matches_t *const pkt_matches)
Get the packet match ICMPV6_CODE value in HOST BYTE ORDER.
static uint32_t packet_matches_get_gtp_teid_value(packet_matches_t *const pkt_matches)
Get the packet match PPP_PROTO value in HOST BYTE ORDER.
static uint32_t packet_matches_get_mpls_label_value(packet_matches_t *const pkt_matches)
Get the packet match MPLS_LABEL value in HOST BYTE ORDER.
static uint64_t packet_matches_get_arp_tha_value(packet_matches_t *const pkt_matches)
Get the packet match ARP_THA value in HOST BYTE ORDER.
static uint32_t packet_matches_get_ipv4_dst_value(packet_matches_t *const pkt_matches)
Get the packet match IP4_DST value in HOST BYTE ORDER.
static uint128__t packet_matches_get_ipv6_dst_value(packet_matches_t *const pkt_matches)
Get the packet match IP6_DST value in HOST BYTE ORDER.
static uint64_t packet_matches_get_wlan_address_1_value(packet_matches_t *const pkt_matches)
Get the packet match WLAN_ADDRESS_1 value in HOST BYTE ORDER.
void fill_packet_matches(struct datapacket *const pkt, packet_matches_t *pkt_matches)
Fill in packet_matches (for PKT_INs)
static uint16_t packet_matches_get_ppp_proto_value(packet_matches_t *const pkt_matches)
Get the packet match PPP_PROTO value in HOST BYTE ORDER.
static uint16_t packet_matches_get_udp_src_value(packet_matches_t *const pkt_matches)
Get the packet match UDP_SRC value in HOST BYTE ORDER.
static uint8_t packet_matches_get_icmpv4_type_value(packet_matches_t *const pkt_matches)
Get the packet match ICMPv4_TYPE value in HOST BYTE ORDER.
static uint32_t packet_matches_get_ipv4_src_value(packet_matches_t *const pkt_matches)
Get the packet match IP4_SRC value in HOST BYTE ORDER.
static uint64_t packet_matches_get_eth_src_value(packet_matches_t *const pkt_matches)
Get the packet match ETH_SRC value in HOST BYTE ORDER.
static uint32_t packet_matches_get_arp_spa_value(packet_matches_t *const pkt_matches)
Get the packet match ARP_SPA value in HOST BYTE ORDER.
static uint16_t packet_matches_get_vlan_vid_value(packet_matches_t *const pkt_matches)
Get the packet match VLAN_VID value in HOST BYTE ORDER according to 1.2 semantics (13th bit is a flag...
static uint8_t packet_matches_get_ip_ecn_value(packet_matches_t *const pkt_matches)
Get the packet match IPC_ECN value in HOST BYTE ORDER.
static uint64_t packet_matches_get_eth_dst_value(packet_matches_t *const pkt_matches)
Get the packet match ETH_DST value in HOST BYTE ORDER.
ROFL_BEGIN_DECLS void dump_packet_matches(struct datapacket *const pkt, bool raw_nbo)
Dump the values of packet (header values)
static uint8_t packet_matches_get_ip_dscp_value(packet_matches_t *const pkt_matches)
Get the packet match IP_DSCP value in HOST BYTE ORDER.
static uint8_t packet_matches_get_icmpv4_code_value(packet_matches_t *const pkt_matches)
Get the packet match ICMPv4_CODE value in HOST BYTE ORDER.
Data packet abstraction.
Definition: datapacket.h:49
static uint16_t packet_matches_get_pppoe_sid_value(packet_matches_t *const pkt_matches)
Get the packet match PPPOE_SESSION value in HOST BYTE ORDER.
static uint64_t packet_matches_get_metadata_value(packet_matches_t *const pkt_matches)
Get the packet match METADATA value in HOST BYTE ORDER.
static uint64_t packet_matches_get_wlan_address_2_value(packet_matches_t *const pkt_matches)
Get the packet match WLAN_ADDRESS_2 value in HOST BYTE ORDER.
static uint8_t packet_matches_get_capwap_rid_value(packet_matches_t *const pkt_matches)
Get the packet match CAPWAP_RID value in HOST BYTE ORDER.
static uint8_t packet_matches_get_pppoe_code_value(packet_matches_t *const pkt_matches)
Get the packet match PPPOE_CODE value in HOST BYTE ORDER.