pkt_captures4.cc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <dhcp/tests/pkt_captures.h>
  16. #include <string>
  17. #include <asiolink/io_address.h>
  18. #include <util/encode/hex.h>
  19. /// @file wireshark.cc
  20. ///
  21. /// @brief contains packet captures imported from Wireshark
  22. ///
  23. /// These are actual packets captured over wire. They are used in various
  24. /// tests.
  25. ///
  26. /// The procedure to export Wireshark -> unit-tests is manual, but rather
  27. /// easy to follow:
  28. /// 1. Open a file in wireshark
  29. /// 2. Find the packet you want to export
  30. /// 3. There's a protocol stack (Frame, Ethernet, IPv6, UDP, DHCPv6, ...)
  31. /// 4. Right click on DHCPv6 -> Copy -> Bytes -> Hex Stream
  32. /// 5. Paste it as: string hex_string="[paste here]";
  33. /// 6. Coding guidelines line restrictions apply, so wrap your code as necessary
  34. /// 7. Make sure you decribe the capture appropriately
  35. /// 8. Follow whatever rest of the methods are doing (set ports, ifaces etc.)
  36. /// 9. To easily copy packet description, click File... -> Extract packet
  37. /// dissections -> as plain text file...
  38. /// (Make sure that the packet is expanded in the view. The text file will
  39. /// contain whatever expansion level you have in the graphical tree.)
  40. using namespace std;
  41. using namespace isc::dhcp;
  42. using namespace isc::asiolink;
  43. namespace isc {
  44. namespace test {
  45. Pkt4Ptr PktCaptures::packetFromCapture(const std::string& hex_string) {
  46. std::vector<uint8_t> bin;
  47. // Decode the hex string and store it in bin (which happens
  48. // to be OptionBuffer format)
  49. isc::util::encode::decodeHex(hex_string, bin);
  50. Pkt4Ptr pkt(new Pkt4(&bin[0], bin.size()));
  51. captureSetDefaultFields(pkt);
  52. return (pkt);
  53. }
  54. void PktCaptures::captureSetDefaultFields(const Pkt4Ptr& pkt) {
  55. pkt->setRemotePort(546);
  56. pkt->setRemoteAddr(IOAddress("10.0.0.2"));
  57. pkt->setLocalPort(0);
  58. pkt->setLocalAddr(IOAddress("10.0.0.1"));
  59. pkt->setIndex(2);
  60. pkt->setIface("eth0");
  61. }
  62. Pkt4Ptr PktCaptures::captureRelayedDiscover() {
  63. /* This is packet 1 from capture
  64. dhcp-val/pcap/docsis-*-CG3000DCR-Registration-Filtered.cap
  65. string exported from Wireshark:
  66. User Datagram Protocol, Src Port: bootps (67), Dst Port: bootps (67)
  67. Source port: bootps (67)
  68. Destination port: bootps (67)
  69. Length: 541
  70. Checksum: 0x2181 [validation disabled]
  71. Bootstrap Protocol
  72. Message type: Boot Request (1)
  73. Hardware type: Ethernet
  74. Hardware address length: 6
  75. Hops: 1
  76. Transaction ID: 0x5d05478d
  77. Seconds elapsed: 0
  78. Bootp flags: 0x0000 (Unicast)
  79. Client IP address: 0.0.0.0 (0.0.0.0)
  80. Your (client) IP address: 0.0.0.0 (0.0.0.0)
  81. Next server IP address: 0.0.0.0 (0.0.0.0)
  82. Relay agent IP address: 10.254.226.1 (10.254.226.1)
  83. Client MAC address: Netgear_b8:15:14 (20:e5:2a:b8:15:14)
  84. Client hardware address padding: 00000000000000000000
  85. Server host name not given
  86. Boot file name not given
  87. Magic cookie: DHCP
  88. Option: (53) DHCP Message Type
  89. Option: (55) Parameter Request List
  90. Option: (60) Vendor class identifier (docsis3.0)
  91. Option: (125) V-I Vendor-specific Information
  92. - suboption 1 (Option Request): requesting option 2
  93. - suboption 5 (Modem Caps): 117 bytes
  94. Option: (43) Vendor-Specific Information (CableLabs)
  95. Option: (61) Client identifier
  96. Option: (57) Maximum DHCP Message Size
  97. Option: (82) Agent Information Option
  98. Option: (255) End */
  99. string hex_string =
  100. "010106015d05478d000000000000000000000000000000000afee20120e52ab8151400"
  101. "0000000000000000000000000000000000000000000000000000000000000000000000"
  102. "0000000000000000000000000000000000000000000000000000000000000000000000"
  103. "0000000000000000000000000000000000000000000000000000000000000000000000"
  104. "0000000000000000000000000000000000000000000000000000000000000000000000"
  105. "0000000000000000000000000000000000000000000000000000000000000000000000"
  106. "0000000000000000000000000000000000000000000000000000638253633501013707"
  107. "0102030407067d3c0a646f63736973332e303a7d7f0000118b7a010102057501010102"
  108. "010303010104010105010106010107010f0801100901030a01010b01180c01010d0200"
  109. "400e0200100f010110040000000211010014010015013f160101170101180104190104"
  110. "1a01041b01201c01021d01081e01201f01102001102101022201012301002401002501"
  111. "01260200ff2701012b59020345434d030b45434d3a45524f55544552040d3242523232"
  112. "39553430303434430504312e3034060856312e33332e30330707322e332e3052320806"
  113. "30303039354209094347333030304443520a074e657467656172fe01083d0fff2ab815"
  114. "140003000120e52ab81514390205dc5219010420000002020620e52ab8151409090000"
  115. "118b0401020300ff";
  116. return (packetFromCapture(hex_string));
  117. }
  118. Pkt4Ptr PktCaptures::captureRelayedDiscover2() {
  119. /* This is packet 5 from capture
  120. dhcp-val/pcap/docsis-*-CG3000DCR-Registration-Filtered.cap
  121. string exported from Wireshark:
  122. User Datagram Protocol, Src Port: bootps (67), Dst Port: bootps (67)
  123. Bootstrap Protocol
  124. Message type: Boot Request (1)
  125. Hardware type: Ethernet (0x01)
  126. Hardware address length: 6
  127. Hops: 1
  128. Transaction ID: 0x5d05478f
  129. Seconds elapsed: 5
  130. Bootp flags: 0x0000 (Unicast)
  131. Client IP address: 0.0.0.0 (0.0.0.0)
  132. Your (client) IP address: 0.0.0.0 (0.0.0.0)
  133. Next server IP address: 0.0.0.0 (0.0.0.0)
  134. Relay agent IP address: 10.254.226.1 (10.254.226.1)
  135. Client MAC address: Netgear_b8:15:15 (20:e5:2a:b8:15:15)
  136. Client hardware address padding: 00000000000000000000
  137. Server host name not given
  138. Boot file name not given
  139. Magic cookie: DHCP
  140. Option: (53) DHCP Message Type
  141. Option: (55) Parameter Request List
  142. Option: (43) Vendor-Specific Information
  143. Option: (60) Vendor class identifier (eRouter1.0)
  144. Option: (15) Domain Name
  145. Option: (61) Client identifier
  146. Option: (57) Maximum DHCP Message Size
  147. Option: (82) Agent Information Option
  148. Option: (255) End */
  149. string hex_string =
  150. "010106015d05478f000500000000000000000000000000000afee20120e52ab8151500"
  151. "0000000000000000000000000000000000000000000000000000000000000000000000"
  152. "0000000000000000000000000000000000000000000000000000000000000000000000"
  153. "0000000000000000000000000000000000000000000000000000000000000000000000"
  154. "0000000000000000000000000000000000000000000000000000000000000000000000"
  155. "0000000000000000000000000000000000000000000000000000000000000000000000"
  156. "000000000000000000000000000000000000000000000000000063825363350101370e"
  157. "480102030406070c0f171a36337a2b63020745524f55544552030b45434d3a45524f55"
  158. "544552040d324252323239553430303434430504312e3034060856312e33332e303307"
  159. "07322e332e305232080630303039354209094347333030304443520a074e6574676561"
  160. "720f0745524f555445523c0a65526f75746572312e300f14687364312e70612e636f6d"
  161. "636173742e6e65742e3d0fff2ab815150003000120e52ab81515390205dc5219010420"
  162. "000002020620e52ab8151409090000118b0401020300ff";
  163. return (packetFromCapture(hex_string));
  164. }
  165. }; // end of isc::test namespace
  166. }; // end of isc namespace