All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
arp-proxy.h
Go to the documentation of this file.
1 #ifndef ARPPROXY_H_
2 #define ARPPROXY_H_
3 
4 #include <cvmx.h>
5 #include <cvmx-wqe.h>
6 #include <cvmx-rwlock.h>
7 #include <common.h>
8 
9 
10 #define ARPTIMER 500ul // Proces ARP timer every 500 ms
11 #define ARPTIMEUNUSED 10000ul // If entry not used for 10000 ms mark it as 'unused'
12 #define NROFARPRETRY 3 // retry count ARP request
13 #define PORT_NOT_INIT 9999 // port value when not initialized
14 #define NROFHASHENTRIES_2POW 8 // 256 entries in hash table (2^8=256)
15 #define HASHENTRYTIMEOUT_MS 180000 // Timeout of hash entry is 180 secs
16 
17 
19 
21 class CARPProxy
22 {
23  public:
25  enum EARPEvent
26  {
30  };
31 
32  static const char* ARPEventToString (EARPEvent eARPEvent)
33  {
34  switch (eARPEvent)
35  {
36  case TIMEOUT: return "TIMEOUT";
37  case ARPCONFLICT: return "ARPCONFLICT";
38  case INVALIDMAC: return "INVALIDMAC";
39  default: return "Unknown ARPEvent Type";
40  }
41  }
42 
44  struct TARPEvent
45  {
46  uint64_t ui64InvalidMAC;
51  };
52 
53  struct TIPVLAN
54  {
58  uint16_t ui16VLAN;
59  uint16_t ui16Dummy;
60  uint64_t ui64GatewayMAC;
61  };
62 
63  // typedef of pointer to callback function
64  typedef void (*PTCallBack)(TARPEvent *, void *);
65  CARPProxy(); // constructor
66  void InitARP(uint32_t ui32PortNr, uint16_t ui16NrOfArpEntries, uint16_t m_ui16NrOfVlans, CCoremask* pcCoremask, PTCallBack pCallBack = NULL, void *pArg = NULL, bool bUseATOMIC_LOCK = false);
67  void ShutdownARP(void);
68  uint64_t GetARP(uint32_t ui32DestIP, uint32_t ui32SrcIP, bool bSendARPRequest, uint16_t &ui16VLAN, int *piIndex=NULL);
69  uint64_t GetARP(uint32_t ui32DestIP, uint32_t ui32SrcIP, int &iEntryIndex, bool bSendARPRequest, uint16_t &ui16VLAN, bool bPersistent = false);
70  uint64_t GetMAC(void); // Get MAC address of hardware port
71  bool PacketInput(cvmx_wqe_t *ptWQE);
72  bool ARPTiming(void);
73  bool LastQueryTimeUpdate(int iIndex);
74  bool AddIPAddress(uint32_t ui32IP, uint32_t ui32GateWay, uint32_t ui32NetMask, uint16_t ui16VLAN);
75  bool GetIPAddress(int iIndex, TIPVLAN *ptIpVlan);
76  bool RemoveIPAddress(uint32_t ui32IP, uint16_t ui16VLAN);
77  static uint16_t ip_sum_calc(uint16_t len_ip_header, unsigned char *buff, uint16_t ui16ChecksumPos = 10);
78  uint32_t SearchForIPInVLAN (uint16_t ui16VLAN, uint32_t ui32IP);
79  bool SearchForVLANInIP (uint32_t ui32IP, uint16_t *pui16VLAN, uint32_t *pui32Netmask, uint32_t *pui32Gateway);
80  bool SearchForBestMatchInIP (uint32_t ui32IP, uint16_t *pui16VLAN, uint32_t *pui32IP, uint32_t *pui32Netmask, uint32_t *pui32Gateway);
81  void ResetARPTable ();
82  void ModifyArpTimeout(uint16_t ui16InUseSeconds, uint16_t ui16UnusedSeconds);
83  void RemoveAllIPAddresses();
84  int GetPortNr();
85  int GetAndAddNrOfHashEntries(int iIncrement);
86  void DisplayArpStats(void);
87  private:
88 
89  uint32_t m_ui32ARPEntryCount;
90 
91  enum EARPState
92  {
93  Empty,
94  Requesting,
95  Done,
96  Refreshing,
97  Unused
98  };
99 
100  typedef struct
101  {
102  uint64_t ui64SearchID;
103  uint64_t ui64TimeOfLastQuery;
104  uint32_t ui32Tag;
105  int iIndex;
106  }TDstIPHash;
107 
108  struct TGlobalVar
109  {
110  int64_t i64HighestIndexUsed;
111  cvmx_rwlock_wp_lock_t tARP_RW_lock; // read/write lock for arp table
112  cvmx_rwlock_wp_lock_t tVLANIP_RW_lock; // read/write lock for VLANIP table
113  int16_t ui16CurrentHashEntry; // Current has entry that will be test for cleaning
114  int16_t ui16NrOfIPVLANEntries; // Nr of entries in the IPVLAN table
115  }*m_pGlobalVarStorage;
116 
117  struct TIPVLAN *m_putIPVLAN;
118 
119  struct TARPEntry
120  {
121  uint64_t ui64MACAddress;
122  uint64_t ui64ArpTimer;
123  uint64_t ui64LastQueryTime;
124  uint64_t ui64ExpiryTime;
125  uint32_t ui32IP;
126  uint32_t ui32Gateway;
127  uint32_t ui32Netmask;
128  EARPState e2ArpState;
129  uint16_t ui16VLAN;
130  uint16_t ui16RetryCount;
131  bool bPersistent;
132  }*m_ptARPEntry;
133 
134  uint64_t m_ui64ARPTimer;
135  uint64_t m_ui64ARPTimerInterval;
136  uint64_t m_ui64ARPUnusedInterval;
137  uint64_t m_ui64UnusedTime, m_ui64InUseTime;
138  uint64_t m_ui64TicksPerMs;
139 
140  uint32_t m_ui32PortNr;
141  uint16_t m_ui16NrOfArpEntries;
142  uint16_t *m_pui16NrOfVlans; // Pointer to nr of entries in IPVLAN table
143  uint16_t m_ui16MaxNrOfVlans; // Max number of allowed entries in IPVLAN table
144  bool m_bUseATOMIC_LOCK;
145  // Callback
146  PTCallBack m_pCallBack;
147  TARPEvent m_tARPEvent;
148  void *m_pCallBackArg;
149 
150  CTashTable<uint64_t, sizeof(TDstIPHash)> m_cDstIPHash; // Hash table for Destination IP lookup
151 
152  CCoremask m_cCoremask;
153 
154  char* m_pcARPMem;
155 
156  // private functions
157  bool SendARPRequest(uint32_t ui32IP, uint16_t VLAN = 0);
158  bool SendARPReply (uint32_t ui32SrcIP, uint32_t ui32DstIP, uint64_t DestMACAddress, uint16_t VLAN = 0);
159  bool SendICMPEchoReply(cvmx_wqe_t *pWQE);
160  bool TestARPTableEntry(int iIndex, uint32_t ui32DestIP, uint16_t ui16VLAN, uint32_t ui32SrcIP, uint64_t &ui64MAC, bool bTestVlan=true);
161  void ClearARPEntry(int iIndex);
162  int16_t MakeARPTableEntry(uint32_t ui32IP, uint32_t ui32Gateway, uint32_t ui32Netmask, uint16_t ui16VLAN, uint64_t ui64MACAddress, bool bSendARPRequest = true, bool bPersistent = false);
163  int SearchForIPInARPTable (uint32_t ui32IP, uint16_t ui16VLAN = 0);
164  uint32_t SearchForGatewayInVLAN (uint16_t ui16VLAN, uint32_t ui32IP, int &iIndex);
165 };
166 #endif /*ARPPROXY_H_*/
EARPEvent eARPEvent
Event of type CARPProxy::EARPEvent.
Definition: arp-proxy.h:50
our ip address is in use by somebody else
Definition: arp-proxy.h:28
static uint16_t ip_sum_calc(uint16_t len_ip_header, unsigned char *buff, uint16_t ui16ChecksumPos=10)
void InitARP(uint32_t ui32PortNr, uint16_t ui16NrOfArpEntries, uint16_t m_ui16NrOfVlans, CCoremask *pcCoremask, PTCallBack pCallBack=NULL, void *pArg=NULL, bool bUseATOMIC_LOCK=false)
bool PacketInput(cvmx_wqe_t *ptWQE)
Received an ARP Reply with dest mac that is not our own.
Definition: arp-proxy.h:29
bool ARPTiming(void)
void ShutdownARP(void)
void RemoveAllIPAddresses()
Sirius ARP IPV4 class.
Definition: arp-proxy.h:21
void DisplayArpStats(void)
void ResetARPTable()
uint32_t ui32IPAddress
Definition: arp-proxy.h:55
uint32_t ui32IPAddress
IP address on which IP conflict or timeout event occurred.
Definition: arp-proxy.h:48
uint16_t ui16Dummy
Definition: arp-proxy.h:59
bool SearchForVLANInIP(uint32_t ui32IP, uint16_t *pui16VLAN, uint32_t *pui32Netmask, uint32_t *pui32Gateway)
uint16_t ui16VLAN
Definition: arp-proxy.h:58
bool RemoveIPAddress(uint32_t ui32IP, uint16_t ui16VLAN)
void ModifyArpTimeout(uint16_t ui16InUseSeconds, uint16_t ui16UnusedSeconds)
EARPEvent
Enumerate the different event types the ARP class generates when calling the ARP callback function vo...
Definition: arp-proxy.h:25
uint32_t SearchForIPInVLAN(uint16_t ui16VLAN, uint32_t ui32IP)
uint64_t GetMAC(void)
Define the event events the ARP class generates when calling the ARP callback function void (*PTCallB...
Definition: arp-proxy.h:44
bool LastQueryTimeUpdate(int iIndex)
bool AddIPAddress(uint32_t ui32IP, uint32_t ui32GateWay, uint32_t ui32NetMask, uint16_t ui16VLAN)
bool SearchForBestMatchInIP(uint32_t ui32IP, uint16_t *pui16VLAN, uint32_t *pui32IP, uint32_t *pui32Netmask, uint32_t *pui32Gateway)
int GetAndAddNrOfHashEntries(int iIncrement)
uint32_t ui32PortNr
Physical port on which the event occurred.
Definition: arp-proxy.h:47
static const char * ARPEventToString(EARPEvent eARPEvent)
Definition: arp-proxy.h:32
uint32_t ui32DefaultGateway
Definition: arp-proxy.h:56
uint64_t ui64InvalidMAC
MAC address in case event type is INVALIDMAC.
Definition: arp-proxy.h:46
uint32_t ui32NetMask
Definition: arp-proxy.h:57
uint32_t ui32VLAN
VLAN on which the event occurred.
Definition: arp-proxy.h:49
void(* PTCallBack)(TARPEvent *, void *)
Definition: arp-proxy.h:64
int GetPortNr()
No reply op ARP Request.
Definition: arp-proxy.h:27
bool GetIPAddress(int iIndex, TIPVLAN *ptIpVlan)
uint64_t GetARP(uint32_t ui32DestIP, uint32_t ui32SrcIP, bool bSendARPRequest, uint16_t &ui16VLAN, int *piIndex=NULL)
uint64_t ui64GatewayMAC
Definition: arp-proxy.h:60