1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License version 2 as 5 * published by the Free Software Foundation; 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 * 16 * Author: John Abraham <john.abraham.in@gmail.com> 17 * Contributions: Makhtar Diouf <makhtar.diouf@gmail.com> 18 */ 19 20 #ifndef ANIMPACKET_H 21 #define ANIMPACKET_H 22 #include "common.h" 23 #include "animatorconstants.h" 24 #include "common.h" 25 #include "timevalue.h" 26 #include "animevent.h" 27 namespace netanim 28 { 29 30 31 class AnimWirelessCircles : public QObject, public QGraphicsEllipseItem 32 { 33 Q_OBJECT 34 Q_PROPERTY (QRectF rect READ rect WRITE setRect) 35 36 }; 37 38 39 struct ArpInfo 40 { ArpInfoArpInfo41 ArpInfo () 42 { 43 type = "null"; 44 sourceMac = "null"; 45 sourceIpv4 = "null"; 46 destMac = "ff:ff:ff:ff:ff:ff"; 47 destIpv4 = "null"; 48 } toStringArpInfo49 QString toString () 50 { 51 return " Arp " + type + 52 " SMac: " + sourceMac + 53 " DMac: " + destMac + 54 " SrcIp : " + sourceIpv4 + 55 " DstIp : " + destIpv4; 56 } toShortStringArpInfo57 QString toShortString () 58 { 59 return QString ("Arp:") + type + " DstIP=" + destIpv4; 60 } 61 QString type; 62 QString sourceMac; 63 QString sourceIpv4; 64 QString destMac; 65 QString destIpv4; 66 }; 67 68 struct PppInfo 69 { toStringPppInfo70 QString toString () 71 { 72 return " PPP"; 73 } toShortStringPppInfo74 QString toShortString () 75 { 76 return "PPP"; 77 } 78 79 }; 80 81 struct EthernetInfo 82 { EthernetInfoEthernetInfo83 EthernetInfo () 84 { 85 sourceMac = "null"; 86 destMac = "null"; 87 } toStringEthernetInfo88 QString toString () 89 { 90 return " Ethernet SMac: " + sourceMac + 91 " DMac: " + destMac; 92 } toShortStringEthernetInfo93 QString toShortString () 94 { 95 return "Ethernet:" + sourceMac + " > " + destMac; 96 } 97 QString sourceMac; 98 QString destMac; 99 }; 100 101 102 struct WifiMacInfo 103 { WifiMacInfoWifiMacInfo104 WifiMacInfo () 105 { 106 type = "null"; 107 toDs = "null"; 108 fromDs = "null"; 109 Da = "null"; 110 Sa = "null"; 111 Bssid = "null"; 112 Ra = "null"; 113 SSid = "null"; 114 assocResponseStatus = "null"; 115 116 } 117 toStringWifiMacInfo118 QString toString () 119 { 120 if (type == "CTL_ACK") 121 return " Wifi CTL_ACK RA:" + Ra; 122 if (type == "CTL_RTS") 123 return " Wifi CTL_RTS RA:" + Ra + " TA:" + Sa; 124 if (type == "CTL_CTS") 125 return " Wifi CTL_CTS RA:" + Ra; 126 QString temp = " Wifi " + type + 127 " FromDS: " + fromDs + 128 " toDS: " + toDs + 129 " DA: " + Da + 130 " SA: " + Sa + 131 " BSSId: " + Bssid; 132 if (type == "MGT_ASSOCIATION_REQUEST") 133 temp += " SSid: " + SSid; 134 135 if (type == "MGT_ASSOCIATION_RESPONSE") 136 temp += " status: " + assocResponseStatus; 137 return temp; 138 } 139 toShortStringWifiMacInfo140 QString toShortString () 141 { 142 QString s = ""; 143 if (type == "CTL_RTS") 144 s = "Wifi:CTL_RTS RA:" + Ra + " TA:" + Sa; 145 if (type == "CTL_CTS") 146 s = "Wifi:CTL_CTS RA:" + Ra; 147 if (type == "MGT_BEACON") 148 s = "Wifi:BEACON ssid" + SSid; 149 if (type == "MGT_ASSOCIATION_REQUEST") 150 s = "Wifi:ASSOC_REQ ssid" + SSid; 151 if (type == "CTL_ACK") 152 s = "Wifi:CTL_ACK RA:" + Ra; 153 else 154 s = "Wifi:" + type; 155 return s; 156 157 158 } 159 QString type; 160 QString toDs; 161 QString fromDs; 162 QString Da; 163 QString Sa; 164 QString Bssid; 165 QString Ra; 166 QString SSid; 167 QString assocResponseStatus; 168 }; 169 170 171 struct Ipv4Info 172 { Ipv4InfoIpv4Info173 Ipv4Info () 174 { 175 176 } toStringIpv4Info177 QString toString () 178 { 179 return " Ipv4 Proto:" + protocol + 180 " SrcIp: " + SrcIp + 181 " DstIp: " + DstIp; 182 } toShortStringIpv4Info183 QString toShortString () 184 { 185 return "IPv4:" + SrcIp + " > " + DstIp; 186 } 187 QString tos; 188 QString Dscp; 189 QString Ecn; 190 QString Ttl; 191 QString Id; 192 QString protocol; 193 QString length; 194 QString SrcIp; 195 QString DstIp; 196 197 }; 198 199 200 201 struct Ipv6Info 202 { Ipv6InfoIpv6Info203 Ipv6Info () 204 { 205 206 } toStringIpv6Info207 QString toString () 208 { 209 return " Ipv6"; 210 } toShortStringIpv6Info211 QString toShortString () 212 { 213 return "IPv6"; 214 } 215 216 }; 217 218 219 struct IcmpInfo 220 { IcmpInfoIcmpInfo221 IcmpInfo () 222 { 223 224 } toStringIcmpInfo225 QString toString () 226 { 227 QString temp; 228 temp += "ICMP type: " + type + 229 "code: " + code; 230 if (type == "3" && code == "3") 231 temp += " DstUnreachable"; 232 return temp; 233 234 } toShortStringIcmpInfo235 QString toShortString () 236 { 237 if ( (type == "3") & (code == "3")) 238 { 239 return "ICMP: Dst Unreachable"; 240 } 241 return "ICMP: type=" + type + " code="+ code; 242 } 243 QString type; 244 QString code; 245 }; 246 247 248 struct UdpInfo 249 { UdpInfoUdpInfo250 UdpInfo () 251 { 252 253 } toStringUdpInfo254 QString toString () 255 { 256 return " UDP " + SPort + " > " + DPort; 257 258 } toShortStringUdpInfo259 QString toShortString () 260 { 261 return "UDP:" + SPort + " > " + DPort; 262 263 } 264 QString length; 265 QString SPort; 266 QString DPort; 267 268 }; 269 270 struct TcpInfo 271 { TcpInfoTcpInfo272 TcpInfo () 273 { 274 275 } toStringTcpInfo276 QString toString () 277 { 278 return " TCP " + SPort + " > " + DPort + 279 " " + flags + " Seq=" + seq + 280 " Ack=" + ack + " Win=" + window; 281 282 } toShortStringTcpInfo283 QString toShortString () 284 { 285 return "TCP:[" + flags + "]" + " S=" + seq + 286 " A=" + ack; 287 } 288 QString SPort; 289 QString DPort; 290 QString flags; 291 QString seq; 292 QString ack; 293 QString window; 294 295 }; 296 297 struct AodvInfo 298 { AodvInfoAodvInfo299 AodvInfo () 300 { 301 302 } toStringAodvInfo303 QString toString () 304 { 305 if (type == "RERR") 306 { 307 return "RERR:" + rerrInfo + " " + destination; 308 } 309 return "AODV:" + type + " D=" + destination + " S=" + source + " Seq=" + seq; 310 } toShortStringAodvInfo311 QString toShortString () 312 { 313 if (type == "RERR") 314 { 315 return "RERR:" + rerrInfo + " " + destination; 316 } 317 return "AODV:" + type + " D=" + destination + " S=" + source + " Seq=" + seq; 318 } 319 QString type; 320 QString destination; 321 QString source; 322 QString seq; 323 QString rerrInfo; 324 }; 325 326 struct DsdvInfo 327 { DsdvInfoDsdvInfo328 DsdvInfo () 329 { 330 331 } toStringDsdvInfo332 QString toString () 333 { 334 return "DSDV"; 335 } toShortStringDsdvInfo336 QString toShortString () 337 { 338 return "DSDV"; 339 } 340 }; 341 342 struct OlsrInfo 343 { OlsrInfoOlsrInfo344 OlsrInfo () 345 { 346 347 } toStringOlsrInfo348 QString toString () 349 { 350 return "OLSR"; 351 } toShortStringOlsrInfo352 QString toShortString () 353 { 354 return "OLSR"; 355 } 356 }; 357 358 359 360 class AnimPacket : public QGraphicsObject 361 { 362 Q_OBJECT 363 Q_PROPERTY (QPointF pos READ pos WRITE setPos) 364 public: 365 AnimPacket (uint32_t fromNodeId, 366 uint32_t toNodeId, 367 qreal firstBitTx, 368 qreal firstBitRx, 369 qreal lastBitTx, 370 qreal lastBitRx, 371 bool isWPacket, 372 QString metaInfo, 373 bool showMetaInfo, 374 uint8_t numWirelessSlots); 375 ~AnimPacket (); 376 377 typedef enum { 378 ALL= 0 << 0, 379 TCP= 1 << 0, 380 UDP= 1 << 1, 381 AODV= 1 << 2, 382 OLSR= 1 << 3, 383 DSDV= 1 << 4, 384 IPV4= 1 << 5, 385 WIFI= 1 << 6, 386 ETHERNET= 1 << 7, 387 PPP= 1 << 8, 388 ICMP= 1 << 9, 389 ARP= 1 << 10, 390 IPV6 = 1 << 11 391 } FilterType_t; 392 enum { Type = ANIMPACKET_TYPE }; type()393 int type () const 394 { 395 return Type; 396 } 397 qreal getFirstBitTx (); 398 qreal getFirstBitRx (); 399 qreal getLastBitRx (); 400 qreal getLastBitTx (); 401 uint32_t getFromNodeId (); 402 uint32_t getToNodeId (); 403 QPointF getFromPos (); 404 QPointF getToPos (); 405 void update (qreal t); 406 virtual QRectF boundingRect () const; 407 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 408 QPointF getHead (); 409 QGraphicsSimpleTextItem * getInfoTextItem (); 410 bool getIsWPacket (); 411 static QString getMeta (QString metaInfo, bool shortString = true); 412 static QString getMeta (QString metaInfo, int filter, bool & result, bool shortString = true); 413 bool packetExpired (); 414 qreal getRadius (); 415 416 417 private: 418 uint32_t m_fromNodeId; 419 uint32_t m_toNodeId; 420 qreal m_firstBitTx; 421 qreal m_firstBitRx; 422 qreal m_lastBitTx; 423 qreal m_lastBitRx; 424 qreal m_velocity; 425 qreal m_isWPacket; 426 qreal m_distanceTraveled; 427 QLineF m_line; 428 qreal m_cos; 429 qreal m_sin; 430 QPointF m_fromPos; 431 QPointF m_toPos; 432 QPointF m_head; 433 QRectF m_boundingRect; 434 QGraphicsSimpleTextItem * m_infoText; 435 qreal m_currentTime; 436 uint8_t m_numWirelessSlots; 437 uint8_t m_currentWirelessSlot; 438 439 440 static ArpInfo parseArp (QString metaInfo, bool & result); 441 static PppInfo parsePpp (QString metaInfo, bool & result); 442 static EthernetInfo parseEthernet (QString metaInfo, bool & result); 443 static WifiMacInfo parseWifi (QString metaInfo, bool & result); 444 static Ipv4Info parseIpv4 (QString metaInfo, bool & result); 445 static Ipv6Info parseIpv6 (QString metaInfo, bool & result); 446 static IcmpInfo parseIcmp (QString metaInfo, bool & result); 447 static UdpInfo parseUdp (QString metaInfo, bool & result); 448 static TcpInfo parseTcp (QString metaInfo, bool & result); 449 static AodvInfo parseAodv (QString metaInfo, bool & result); 450 static DsdvInfo parseDsdv (QString metaInfo, bool & result); 451 static OlsrInfo parseOlsr (QString metaInfo, bool & result); 452 453 }; 454 455 class AnimPacketMgr 456 { 457 public: 458 static AnimPacketMgr * getInstance (); 459 AnimPacket * add (uint32_t fromId, uint32_t toId, qreal fbTx, qreal fbRx, qreal lbTx, qreal lbRx, bool isWPacket, QString metaInfo, bool showMetaInfo, uint8_t numWirelessSlots); 460 private: 461 AnimPacketMgr (); 462 463 464 }; 465 466 } 467 #endif // ANIMPACKET_H 468