2#ifndef CLICK_ICMPFlowID_HH
3#define CLICK_ICMPFlowID_HH
5#include <click/hashcode.hh>
6#include <clicknet/ip.h>
7#include <clicknet/icmp.h>
11class ICMPFlowID {
public:
13 typedef uninitialized_type uninitialized_t;
20 : _saddr(), _daddr(), _id(0), _seq(0) {
29 : _saddr(saddr), _daddr(daddr), _id(id), _seq(seq) {
32 inline explicit ICMPFlowID(
const Packet *p,
bool reverse =
false);
33 inline explicit ICMPFlowID(
const click_ip *iph,
bool reverse =
false);
36 inline ICMPFlowID(
const uninitialized_type &unused) {
41 typedef IPAddress (ICMPFlowID::*unspecified_bool_type)() const;
43 operator unspecified_bool_type()
const {
44 return _saddr || _daddr ? &ICMPFlowID::saddr : 0;
59 uint16_t seq()
const {
87 ICMPFlowID reverse()
const {
88 return ICMPFlowID(_daddr,_saddr, _id, _seq);
90 inline ICMPFlowID rev() const CLICK_DEPRECATED;
96 inline hashcode_t hashcode() const;
107 int unparse(
char *s) const;
113inline ICMPFlowID ICMPFlowID::rev()
const
119#define ROT(v, r) ((v)<<(r) | ((unsigned)(v))>>(32-(r)))
121inline hashcode_t ICMPFlowID::hashcode()
const
124 uint16_t s = ntohs(
id());
125 uint16_t d = ntohs(seq());
126 hashcode_t sx = CLICK_NAME(hashcode)(saddr());
127 hashcode_t dx = CLICK_NAME(hashcode)(daddr());
128 return (ROT(sx, (s % 16) + 1) ^ ROT(dx, 31 - (d % 16)))
134inline bool operator==(
const ICMPFlowID &a,
const ICMPFlowID &b)
136 return a.seq() == b.seq() && a.id() == b.id()
137 && a.saddr() == b.saddr() && a.daddr() == b.daddr();
140inline bool operator!=(
const ICMPFlowID &a,
const ICMPFlowID &b)
142 return a.seq() != b.seq() || a.id() != b.id()
143 || a.saddr() != b.saddr() || a.daddr() != b.daddr();
149ICMPFlowID::ICMPFlowID(
const Packet *p,
bool reverse)
152 const click_icmp_sequenced *icmph =
reinterpret_cast<const click_icmp_sequenced*
>(p->
transport_header());
154 && IP_FIRSTFRAG(iph));
156 if (likely(!reverse))
157 assign(iph->ip_src.s_addr,
158 iph->ip_dst.s_addr, icmph->icmp_identifier, icmph->icmp_sequence);
160 assign(iph->ip_dst.s_addr,
161 iph->ip_src.s_addr, icmph->icmp_identifier, icmph->icmp_sequence);
165ICMPFlowID::ICMPFlowID(
const click_ip *iph,
bool reverse)
167 const click_icmp_sequenced *icmph =
reinterpret_cast<const click_icmp_sequenced*
>(iph + 1);
168 assert(IP_FIRSTFRAG(iph));
170 if (likely(!reverse))
171 assign(iph->ip_src.s_addr,
172 iph->ip_dst.s_addr, icmph->icmp_identifier, icmph->icmp_sequence);
174 assign(iph->ip_dst.s_addr,
175 iph->ip_src.s_addr, icmph->icmp_identifier, icmph->icmp_sequence);
An IPv4 address.
Definition ipaddress.hh:16
A network packet.
Definition packet.hh:68
const click_ip * ip_header() const
Return the packet's network header pointer as IPv4.
Definition packet.hh:1523
bool has_transport_header() const
Return true iff the packet's transport header pointer is set.
Definition packet.hh:1473
const unsigned char * transport_header() const
Return the packet's transport header pointer.
Definition packet.hh:1495
bool has_network_header() const
Return true iff the packet's network header pointer is set.
Definition packet.hh:1435
Efficiently build up Strings from pieces.
Definition straccum.hh:28
The IPAddress type for IPv4 addresses.