1 //=========================================================================== 2 // $Name: arts++-1-1-a13 $ 3 // $Id: Arts.hh,v 1.2 2004/04/21 23:51:24 kkeys Exp $ 4 //=========================================================================== 5 // Copyright Notice 6 // 7 // By accessing this software, arts++, you are duly informed 8 // of and agree to be bound by the conditions described below in this 9 // notice: 10 // 11 // This software product, arts++, is developed by Daniel W. McRobb, and 12 // copyrighted(C) 1998 by the University of California, San Diego 13 // (UCSD), with all rights reserved. UCSD administers the CAIDA grant, 14 // NCR-9711092, under which part of this code was developed. 15 // 16 // There is no charge for arts++ software. You can redistribute it 17 // and/or modify it under the terms of the GNU Lesser General Public 18 // License, Version 2.1, February 1999, which is incorporated by 19 // reference herein. 20 // 21 // arts++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF 22 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use 23 // of it will not infringe on any third party's intellectual 24 // property rights. 25 // 26 // You should have received a copy of the GNU Lesser General Public 27 // License along with arts++. Copies can also be obtained from: 28 // 29 // http://www.gnu.org/copyleft/lesser.html 30 // 31 // or by writing to: 32 // 33 // Free Software Foundation, Inc. 34 // 59 Temple Place, Suite 330 35 // Boston, MA 02111-1307 36 // USA 37 // 38 // Or contact: 39 // 40 // info@caida.org 41 //=========================================================================== 42 43 #ifndef _ARTS_HH_ 44 #define _ARTS_HH_ 45 46 #include <vector> 47 #include <string> 48 49 #include "ArtsHeader.hh" 50 #include "ArtsAttributeVector.hh" 51 #include "ArtsIpPathData.hh" 52 #include "ArtsAsMatrixData.hh" 53 #include "ArtsNetMatrixData.hh" 54 #include "ArtsPortTableData.hh" 55 #include "ArtsPortMatrixData.hh" 56 #include "ArtsProtocolTableData.hh" 57 #include "ArtsSelectedPortTableData.hh" 58 #include "ArtsTosTableData.hh" 59 #include "ArtsInterfaceMatrixData.hh" 60 #include "ArtsNextHopTableData.hh" 61 #include "ArtsBgp4RouteTableData.hh" 62 #include "ArtsRttTimeSeriesTableData.hh" 63 64 //--------------------------------------------------------------------------- 65 // class Arts 66 //--------------------------------------------------------------------------- 67 //! Top-level Arts class. The most frequent instantiation of this class: 68 //! an application needs to deal with an Arts object whose type is not 69 //! known until runtime. For example, reading a file containing ARTS 70 //! objects of arbitrary type or order. 71 // 72 //! In cases where an application knows what type of Arts object it 73 //! needs, it should instantiate the derived class and not this class. 74 //--------------------------------------------------------------------------- 75 class Arts 76 { 77 public: 78 //------------------------------------------------------------------------- 79 // Arts() 80 //......................................................................... 81 //! constructor 82 //------------------------------------------------------------------------- 83 Arts(); 84 85 //-------------------------------------------------------------------------- 86 // Arts(const Arts & arts) 87 //.......................................................................... 88 //! copy constructor 89 //-------------------------------------------------------------------------- 90 Arts(const Arts & arts); 91 92 //------------------------------------------------------------------------- 93 // ~Arts() 94 //......................................................................... 95 //! destructor 96 //------------------------------------------------------------------------- 97 ~Arts(); 98 99 //------------------------------------------------------------------------- 100 // void AddHostAttribute(ipv4addr_t hostAddr) 101 //......................................................................... 102 //! Adds a host attribute with an IP address of hostAddr. 103 //------------------------------------------------------------------------- 104 void AddHostAttribute(ipv4addr_t hostAddr); 105 106 //-------------------------------------------------------------------------- 107 // void AddHostPairAttribute(ipv4addr_t host1, ipv4addr_t host2) 108 //.......................................................................... 109 //! Adds a host pair attribute. 110 //-------------------------------------------------------------------------- 111 void AddHostPairAttribute(ipv4addr_t host1, ipv4addr_t host2); 112 113 //------------------------------------------------------------------------- 114 // void AddCreationAttribute(uint32_t creationTime); 115 //......................................................................... 116 //! Adds a creation time attribute. 117 //------------------------------------------------------------------------- 118 void AddCreationAttribute(uint32_t creationTime); 119 120 //------------------------------------------------------------------------- 121 // void AddPeriodAttribute(uint32_t startTime, uint32_t endTime) 122 //......................................................................... 123 //! Adds a period attribute (startTime to endTime). 124 //------------------------------------------------------------------------- 125 void AddPeriodAttribute(uint32_t startTime, uint32_t endTime); 126 127 //------------------------------------------------------------------------- 128 // void AddIfIndexAttribute(uint16_t ifIndex) 129 //......................................................................... 130 //! Adds an interface index attribute using ifIndex as value. 131 //------------------------------------------------------------------------- 132 void AddIfIndexAttribute(uint16_t ifIndex); 133 134 //-------------------------------------------------------------------------- 135 // void AddIfDescrAttribute(const std::string & ifDescr) 136 //.......................................................................... 137 //! Adds an interface description attribute using ifDescr as value. 138 //-------------------------------------------------------------------------- 139 void AddIfDescrAttribute(const std::string & ifDescr); 140 141 //-------------------------------------------------------------------------- 142 // void AddIfIpAddrAttribute(ipv4addr_t ipAddr) 143 //.......................................................................... 144 //! Adds an interface IP address attribute using ipAddr as value. 145 //-------------------------------------------------------------------------- 146 void AddIfIpAddrAttribute(ipv4addr_t ipAddr); 147 148 //------------------------------------------------------------------------- 149 // inline ArtsHeader & Header() const 150 //......................................................................... 151 //! Returns a reference to the header data. 152 //------------------------------------------------------------------------- Header() const153 inline ArtsHeader & Header() const 154 { 155 return(this->_header); 156 } 157 158 //------------------------------------------------------------------------- 159 // inline ArtsAttributeVector & Attributes() const 160 //......................................................................... 161 //! Returns a reference to the vector of attributes. 162 //------------------------------------------------------------------------- Attributes() const163 inline ArtsAttributeVector & Attributes() const 164 { 165 return(this->_attributes); 166 } 167 168 //------------------------------------------------------------------------- 169 // ArtsAttributeVector::const_iterator FindCreationAttribute() const 170 //......................................................................... 171 //! Returns an iterator for the first creation attribute in the object. 172 //! If a creation attribute is not found, returns this->Attributes().end() 173 //------------------------------------------------------------------------- 174 ArtsAttributeVector::const_iterator FindCreationAttribute() const; 175 176 //-------------------------------------------------------------------------- 177 // bool RemoveCreationAttribute() 178 //.......................................................................... 179 //! Removes the creation time attribute (if it exists) from the Arts 180 //! object and returns true. If the Arts object does not contain a 181 //! creation time attribute, returns false. 182 //-------------------------------------------------------------------------- 183 bool RemoveCreationAttribute(); 184 185 //------------------------------------------------------------------------- 186 // ArtsAttributeVector::const_iterator FindPeriodAttribute() const 187 //......................................................................... 188 //! Returns an iterator for the first period attribute in the object. 189 //! If a period attribute is not found, returns this->Attributes().end() 190 //------------------------------------------------------------------------- 191 ArtsAttributeVector::const_iterator FindPeriodAttribute() const; 192 193 //-------------------------------------------------------------------------- 194 // bool RemovePeriodAttribute() 195 //.......................................................................... 196 //! Removes the period attribute (if it exists) from the Arts object 197 //! and returns true. If the Arts object does not contain a period 198 //! attribute, returns false. 199 //-------------------------------------------------------------------------- 200 bool RemovePeriodAttribute(); 201 202 //------------------------------------------------------------------------- 203 // ArtsAttributeVector::const_iterator FindHostAttribute() const 204 //......................................................................... 205 //! Returns an iterator for the first host attribute in the object. 206 //! If a host attribute is not found, returns this->Attributes().end() 207 //------------------------------------------------------------------------- 208 ArtsAttributeVector::const_iterator FindHostAttribute() const; 209 210 //-------------------------------------------------------------------------- 211 // bool RemoveHostAttribute() 212 //.......................................................................... 213 //! Removes the host attribute (if it exists) from the Arts object 214 //! and returns true. If the Arts object does not contain a host 215 //! attribute, returns false. 216 //-------------------------------------------------------------------------- 217 bool RemoveHostAttribute(); 218 219 //-------------------------------------------------------------------------- 220 // ArtsAttributeVector::const_iterator FindHostPairAttribute() const 221 //.......................................................................... 222 //! Returns an iterator for the first host pair attribute in the 223 //! object. If a host pair attribute is not found, returns 224 //! this->Attributes().end() 225 //-------------------------------------------------------------------------- 226 ArtsAttributeVector::const_iterator FindHostPairAttribute() const; 227 228 //-------------------------------------------------------------------------- 229 // bool RemoveHostPairAttribute() 230 //.......................................................................... 231 //! Removes the host pair attribute (if it exists) from the Arts 232 //! object and returns true. If the Arts object does not contain a 233 //! host pair attribute, returns false. 234 //-------------------------------------------------------------------------- 235 bool RemoveHostPairAttribute(); 236 237 //------------------------------------------------------------------------- 238 // ArtsAttributeVector::const_iterator FindIfIndexAttribute() const 239 //......................................................................... 240 //! returns an iterator for the first interface index attribute in 241 //! the object. If an interface index attribute is not found, returns 242 //! this->Attributes().end() 243 //------------------------------------------------------------------------- 244 ArtsAttributeVector::const_iterator FindIfIndexAttribute() const; 245 246 //-------------------------------------------------------------------------- 247 // bool RemoveIfIndexAttribute() 248 //.......................................................................... 249 //! Removes the interface index attribute (if it exists) from the Arts 250 //! object and returns true. If the Arts object does not contain an 251 //! interface index attribute, returns false. 252 //-------------------------------------------------------------------------- 253 bool RemoveIfIndexAttribute(); 254 255 //-------------------------------------------------------------------------- 256 // ArtsAttributeVector::const_iterator FindIfDescrAttribute() const 257 //.......................................................................... 258 //! returns an iterator for the first interface description attribute 259 //! in the object. If an interface description attribute is not found, 260 //! returns this->Attributes().end() 261 //-------------------------------------------------------------------------- 262 ArtsAttributeVector::const_iterator FindIfDescrAttribute() const; 263 264 //-------------------------------------------------------------------------- 265 // bool RemoveIfDescrAttribute() 266 //.......................................................................... 267 //! Removes the interface description attribute (if it exists) from 268 //! the Arts object and returns true. If the Arts object does not 269 //! contain an interface description attribute, returns false. 270 //-------------------------------------------------------------------------- 271 bool RemoveIfDescrAttribute(); 272 273 //-------------------------------------------------------------------------- 274 // ArtsAttributeVector::const_iterator FindIfIpAddrAttribute() const 275 //.......................................................................... 276 //! returns an iterator for the first interface IP address attribute 277 //! in the object. If an interface IP address attribute is not found, 278 //! returns this->Attributes().end() 279 //-------------------------------------------------------------------------- 280 ArtsAttributeVector::const_iterator FindIfIpAddrAttribute() const; 281 282 //-------------------------------------------------------------------------- 283 // bool RemoveIfIpAddrAttribute() 284 //.......................................................................... 285 //! Removes the interface IP address attribute (if it exists) from 286 //! the Arts object and returns true. If the Arts object does not 287 //! contain an interface IP address attribute, returns false. 288 //-------------------------------------------------------------------------- 289 bool RemoveIfIpAddrAttribute(); 290 291 //------------------------------------------------------------------------- 292 // inline ArtsIpPathData* IpPathData() const 293 //......................................................................... 294 //! Returns a pointer to the IP path data in an object containing 295 //! ArtsIpPathData. If the object is not holding ArtsIpPathData, 296 //! returns NULL. 297 //------------------------------------------------------------------------- IpPathData() const298 inline ArtsIpPathData* IpPathData() const 299 { 300 return(this->_data._ipPath); 301 } 302 303 //------------------------------------------------------------------------- 304 // inline ArtsAsMatrixData* AsMatrixData() const 305 //......................................................................... 306 //! Returns a pointer to the AS matrix data in an object. Returns NULL 307 //! if there is no AS matrix data in the object. 308 //------------------------------------------------------------------------- AsMatrixData() const309 inline ArtsAsMatrixData* AsMatrixData() const 310 { 311 return(this->_data._asMatrix); 312 } 313 314 //------------------------------------------------------------------------- 315 // inline ArtsNetMatrixData* NetMatrixData() const 316 //......................................................................... 317 //! Returns a pointer to the AS matrix data in an object. Returns NULL 318 //! if there is no AS matrix data in the object. 319 //------------------------------------------------------------------------- NetMatrixData() const320 inline ArtsNetMatrixData* NetMatrixData() const 321 { 322 return(this->_data._netMatrix); 323 } 324 325 //------------------------------------------------------------------------- 326 // inline ArtsPortTableData* PortTableData() const 327 //......................................................................... 328 //! Returns a pointer to the port table in the object. Returns NULL if 329 //! there is no port table in the object. 330 //------------------------------------------------------------------------- PortTableData() const331 inline ArtsPortTableData* PortTableData() const 332 { 333 return(this->_data._portTable); 334 } 335 336 //------------------------------------------------------------------------- 337 // inline ArtsSelectedPortTableData* SelectedPortTableData() const 338 //......................................................................... 339 //! Returns a pointer to the selected port table in the object. 340 //! Returns NULL if there is no selected port table in the object. 341 //------------------------------------------------------------------------- SelectedPortTableData() const342 inline ArtsSelectedPortTableData* SelectedPortTableData() const 343 { 344 return(this->_data._selectedPortTable); 345 } 346 347 //------------------------------------------------------------------------- 348 // inline ArtsPortMatrixData* PortMatrixData() const 349 //......................................................................... 350 //! Returns a pointer to the port matrix in the object. Returns NULL 351 //! if there is no port matrix in the object. 352 //------------------------------------------------------------------------- PortMatrixData() const353 inline ArtsPortMatrixData* PortMatrixData() const 354 { 355 return(this->_data._portMatrix); 356 } 357 358 //------------------------------------------------------------------------- 359 // inline ArtsProtocolTableData* ProtocolTableData() const 360 //......................................................................... 361 //! Returns a pointer to the protocol table in the object. Returns 362 //! NULL if there is no protocol table in the object. 363 //------------------------------------------------------------------------- ProtocolTableData() const364 inline ArtsProtocolTableData* ProtocolTableData() const 365 { 366 return(this->_data._protocolTable); 367 } 368 369 //-------------------------------------------------------------------------- 370 // inline ArtsTosTableData * TosTableData() const 371 //.......................................................................... 372 //! Returns a pointer to the TOS table in the object. Returns NULL if 373 //! there is no TOS table in the object. 374 //-------------------------------------------------------------------------- TosTableData() const375 inline ArtsTosTableData * TosTableData() const 376 { 377 return(this->_data._tosTable); 378 } 379 380 //------------------------------------------------------------------------- 381 // inline ArtsInterfaceMatrixData * InterfaceMatrixData() const 382 //......................................................................... 383 //! Returns a pointer to the interface matrix in the object. Returns 384 //! NULL if there is no interface matrix in the object. 385 //------------------------------------------------------------------------- InterfaceMatrixData() const386 inline ArtsInterfaceMatrixData * InterfaceMatrixData() const 387 { 388 return(this->_data._interfaceMatrix); 389 } 390 391 //------------------------------------------------------------------------- 392 // inline ArtsNextHopTableData * NextHopTableData() const 393 //......................................................................... 394 //! Returns a pointer to the IP nexthop table in the object. Returns 395 //! NULL if there is no IP nexthop table in the object. 396 //------------------------------------------------------------------------- NextHopTableData() const397 inline ArtsNextHopTableData * NextHopTableData() const 398 { 399 return(this->_data._nextHopTable); 400 } 401 402 //-------------------------------------------------------------------------- 403 // inline ArtsBgp4RouteTableData * Bgp4RouteTableData() const 404 //.......................................................................... 405 //! Returns a pointer to the BGP4 route table in the object. Returns 406 //! NULL if there is no BGP4 route table in the object. 407 //-------------------------------------------------------------------------- Bgp4RouteTableData() const408 inline ArtsBgp4RouteTableData * Bgp4RouteTableData() const 409 { 410 return(this->_data._bgp4RouteTable); 411 } 412 413 //-------------------------------------------------------------------------- 414 // inline ArtsRttTimeSeriesTableData * RttTimeSeriesTableData() const 415 //.......................................................................... 416 //! Returns a pointer to the RTT time series table in the object. 417 //! Returns NULL if there is no RTT time series table in the object. 418 //-------------------------------------------------------------------------- RttTimeSeriesTableData() const419 inline ArtsRttTimeSeriesTableData * RttTimeSeriesTableData() const 420 { 421 return(this->_data._rttTimeSeriesTable); 422 } 423 424 //-------------------------------------------------------------------------- 425 // std::istream & readData(std::istream & is) 426 //.......................................................................... 427 // 428 //-------------------------------------------------------------------------- 429 std::istream & readData(std::istream & is); 430 431 //-------------------------------------------------------------------------- 432 // int readData(int fd) 433 //.......................................................................... 434 // 435 //-------------------------------------------------------------------------- 436 int readData(int fd); 437 438 //------------------------------------------------------------------------- 439 // std::istream& read(std::istream& is) 440 //......................................................................... 441 //! Loads the data from an istream into the Arts object. Returns a 442 //! reference to the istream. 443 //------------------------------------------------------------------------- 444 std::istream & read(std::istream & is); 445 446 //------------------------------------------------------------------------- 447 // int read(int fd) 448 //......................................................................... 449 //! Loads the data from a file descriptor into the Arts object. 450 //! Returns the number of bytes read on success, -1 on failure. 451 //------------------------------------------------------------------------- 452 int read(int fd); 453 454 //------------------------------------------------------------------------- 455 // std::ostream& write(std::ostream& os) 456 //......................................................................... 457 //! Writes an Arts object to an ostream. Returns a reference to the 458 //! ostream. 459 //------------------------------------------------------------------------- 460 std::ostream& write(std::ostream& os); 461 462 //------------------------------------------------------------------------- 463 // int write(int fd) 464 //......................................................................... 465 //! Writes an Arts object to a file descriptor. Returns the number 466 //! of bytes written on success, -1 on failure. 467 //------------------------------------------------------------------------- 468 int write(int fd); 469 470 //------------------------------------------------------------------------- 471 // Arts & operator = (const Arts & arts) 472 //......................................................................... 473 //! Overloaded '=' operator to deep-copy an ARTS object. 474 //------------------------------------------------------------------------- 475 Arts & operator = (const Arts & arts); 476 477 //------------------------------------------------------------------------- 478 // friend std::ostream & operator << (std::ostream & os, 479 // const Arts & arts) 480 //......................................................................... 481 //! Overloaded ostream '<<' operator to dump the contents of an Arts 482 //! object to an ostream in a human-readable form. Returns the 483 //! ostream. 484 //------------------------------------------------------------------------- 485 friend std::ostream & operator << (std::ostream & os, 486 const Arts & arts); 487 488 //-------------------------------------------------------------------------- 489 // friend std::istream & operator >> (std::istream & is, 490 // Arts & arts) 491 //.......................................................................... 492 //! This works just like our read(is) member, but lets us use 493 //! istream_iterator<Arts> to walk through Arts objects in an istream. 494 //-------------------------------------------------------------------------- 495 friend std::istream & operator >> (std::istream & is, 496 Arts & arts); 497 498 //-------------------------------------------------------------------------- 499 // void DeleteData() 500 //.......................................................................... 501 // Deletes data contained in Arts object. 502 //-------------------------------------------------------------------------- 503 void DeleteData(); 504 505 #ifndef NDEBUG 506 //------------------------------------------------------------------------ 507 // static uint32_t NumObjects() 508 //........................................................................ 509 // 510 //------------------------------------------------------------------------ NumObjects()511 static uint32_t NumObjects() 512 { 513 return(_numObjects); 514 } 515 #endif 516 517 protected: 518 struct { 519 ArtsIpPathData* _ipPath; 520 ArtsAsMatrixData* _asMatrix; 521 ArtsPortTableData* _portTable; 522 ArtsProtocolTableData* _protocolTable; 523 ArtsNetMatrixData* _netMatrix; 524 ArtsPortMatrixData* _portMatrix; 525 ArtsSelectedPortTableData* _selectedPortTable; 526 ArtsInterfaceMatrixData* _interfaceMatrix; 527 ArtsNextHopTableData* _nextHopTable; 528 ArtsBgp4RouteTableData* _bgp4RouteTable; 529 ArtsRttTimeSeriesTableData* _rttTimeSeriesTable; 530 ArtsTosTableData* _tosTable; 531 } _data; 532 533 mutable ArtsHeader _header; 534 mutable ArtsAttributeVector _attributes; 535 536 //-------------------------------------------------------------------------- 537 // void DeleteAttributes() 538 //.......................................................................... 539 // Deletes attributes contained in Arts object. 540 //-------------------------------------------------------------------------- 541 void DeleteAttributes(); 542 543 static uint32_t _numObjects; 544 }; 545 546 #endif /* _ARTS_HH_ */ 547 548