Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include <cstdlib> |
| 8 | #include <sstream> |
| 9 | #include <iostream> |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 10 | #include <ndn-cpp/interest.hpp> |
| 11 | #include <ndn-cpp/data.hpp> |
| 12 | #include <ndn-cpp/forwarding-entry.hpp> |
| 13 | #include <ndn-cpp/security/key-chain.hpp> |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 14 | |
| 15 | using namespace std; |
| 16 | using namespace ndn; |
| 17 | |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 18 | uint8_t Interest1[] = { |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 19 | 0x01, 0xd2, 0xf2, 0xfa, 0xa5, 0x6e, 0x64, 0x6e, 0x78, 0x00, 0xfa, 0x02, 0x85, 0xe0, 0xa0, 0x1e, 0x09, 0x39, 0x68, |
| 20 | 0xf9, 0x74, 0x0c, 0xe7, 0xf4, 0x36, 0x1b, 0xab, 0xf5, 0xbb, 0x05, 0xa4, 0xe5, 0x5a, 0xac, 0xa5, 0xe5, 0x8f, 0x73, |
| 21 | 0xed, 0xde, 0xb8, 0xe0, 0x13, 0xaa, 0x8f, 0x00, 0xfa, 0xcd, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x72, 0x65, 0x67, |
| 22 | 0x00, 0xfa, 0x29, 0xad, 0x04, 0x82, 0x02, 0xaa, 0x03, 0xb2, 0x08, 0x85, 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b5, 0x04, 0xfc, 0xe9, 0xe2, |
| 32 | 0x53, 0xd7, 0x00, 0x01, 0xe2, 0x01, 0x82, 0x19, 0xfd, 0x30, 0x82, 0x01, 0x9b, 0x30, 0x82, 0x01, 0x04, 0x02, 0x09, |
| 33 | 0x00, 0xb7, 0xd8, 0x5c, 0x90, 0x6b, 0xad, 0x52, 0xee, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, |
| 34 | 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, 0x61, |
| 35 | 0x78, 0x65, 0x6c, 0x63, 0x64, 0x76, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x32, 0x30, 0x34, 0x32, 0x38, 0x32, 0x33, 0x34, |
| 36 | 0x34, 0x33, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x32, 0x30, 0x35, 0x32, 0x38, 0x32, 0x33, 0x34, 0x34, 0x33, 0x37, 0x5a, |
| 37 | 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, 0x61, 0x78, 0x65, 0x6c, 0x63, 0x64, |
| 38 | 0x76, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, |
| 39 | 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xe1, 0x7d, 0x30, 0xa7, 0xd8, 0x28, 0xab, 0x1b, |
| 40 | 0x84, 0x0b, 0x17, 0x54, 0x2d, 0xca, 0xf6, 0x20, 0x7a, 0xfd, 0x22, 0x1e, 0x08, 0x6b, 0x2a, 0x60, 0xd1, 0x6c, 0xb7, |
| 41 | 0xf5, 0x44, 0x48, 0xba, 0x9f, 0x3f, 0x08, 0xbc, 0xd0, 0x99, 0xdb, 0x21, 0xdd, 0x16, 0x2a, 0x77, 0x9e, 0x61, 0xaa, |
| 42 | 0x89, 0xee, 0xe5, 0x54, 0xd3, 0xa4, 0x7d, 0xe2, 0x30, 0xbc, 0x7a, 0xc5, 0x90, 0xd5, 0x24, 0x06, 0x7c, 0x38, 0x98, |
| 43 | 0xbb, 0xa6, 0xf5, 0xdc, 0x43, 0x60, 0xb8, 0x45, 0xed, 0xa4, 0x8c, 0xbd, 0x9c, 0xf1, 0x26, 0xa7, 0x23, 0x44, 0x5f, |
| 44 | 0x0e, 0x19, 0x52, 0xd7, 0x32, 0x5a, 0x75, 0xfa, 0xf5, 0x56, 0x14, 0x4f, 0x9a, 0x98, 0xaf, 0x71, 0x86, 0xb0, 0x27, |
| 45 | 0x86, 0x85, 0xb8, 0xe2, 0xc0, 0x8b, 0xea, 0x87, 0x17, 0x1b, 0x4d, 0xee, 0x58, 0x5c, 0x18, 0x28, 0x29, 0x5b, 0x53, |
| 46 | 0x95, 0xeb, 0x4a, 0x17, 0x77, 0x9f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, |
| 47 | 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0xcb, 0x3a, 0xb0, 0x35, 0x7d, 0x7c, 0xd2, 0xae, |
| 48 | 0x97, 0xed, 0x50, 0x1e, 0x51, 0xa3, 0xa0, 0xe2, 0x81, 0x7d, 0x41, 0x8e, 0x47, 0xfb, 0x17, 0x90, 0x64, 0x77, 0xaf, |
| 49 | 0x61, 0x49, 0x5a, 0x7e, 0x8d, 0x87, 0x89, 0x14, 0x10, 0x65, 0xb0, 0x82, 0xd0, 0x01, 0xf4, 0xb1, 0x51, 0x93, 0xd0, |
| 50 | 0xb4, 0x3f, 0xb6, 0x61, 0xcd, 0xe2, 0x0a, 0x64, 0x98, 0x37, 0x2c, 0x6a, 0xbb, 0xd3, 0xdc, 0xb9, 0xf0, 0xd1, 0x26, |
| 51 | 0x59, 0xef, 0x07, 0xb3, 0xc6, 0xdb, 0xdf, 0x8b, 0xdf, 0x2f, 0x65, 0x47, 0x7e, 0xed, 0x7a, 0xdc, 0xd4, 0x57, 0xd7, |
| 52 | 0x93, 0xb1, 0xc2, 0x7b, 0xad, 0xda, 0x7c, 0x5a, 0xde, 0x80, 0xce, 0x95, 0xb7, 0xd8, 0x82, 0x7f, 0xe7, 0x8c, 0x8a, |
| 53 | 0x35, 0xf3, 0xfb, 0x4b, 0xa6, 0x48, 0xa0, 0x81, 0xbe, 0x2c, 0xfe, 0x84, 0x23, 0x1a, 0xba, 0xb3, 0xc2, 0xb5, 0x31, |
| 54 | 0x74, 0x6d, 0xf2, 0xe0, 0x49, 0x2b, 0x00, 0x00, 0x00, 0x01, 0x9a, 0x02, 0xd5, 0x05, 0x8a, 0x04, 0xca, 0xbe, 0x73, |
| 55 | 0x65, 0x6c, 0x66, 0x72, 0x65, 0x67, 0x00, 0xf2, 0xfa, 0xa5, 0x6d, 0x65, 0x6b, 0x69, 0x00, 0x00, 0x04, 0xfa, 0x8e, |
| 56 | 0x33, 0x00, 0x03, 0xd2, 0xd6, 0x32, 0x31, 0x34, 0x37, 0x34, 0x38, 0x33, 0x36, 0x34, 0x37, 0x00, 0x00, 0x00, 0x00, |
| 57 | 0x00, 0x00, 0x02, 0xd2, 0x8e, 0x31, 0x00, 0x00, |
| 58 | 1 |
| 59 | }; |
| 60 | |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 61 | static inline string toString(const vector<uint8_t>& v) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 62 | { |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 63 | if (!&v) |
| 64 | return ""; |
| 65 | |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 66 | return string(&v[0], &v[0] + v.size()); |
| 67 | } |
| 68 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 69 | static void dumpForwardingEntry(const ForwardingEntry& forwardingEntry) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 70 | { |
| 71 | cout << "action: " << forwardingEntry.getAction() << endl; |
| 72 | cout << "prefix: " << forwardingEntry.getPrefix().to_uri() << endl; |
| 73 | cout << "publisherPublicKeyDigest: " |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 74 | << (forwardingEntry.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ? toHex(*forwardingEntry.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()) : "<none>") << endl; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 75 | cout << "faceId: "; |
| 76 | if (forwardingEntry.getFaceId() >= 0) |
| 77 | cout << forwardingEntry.getFaceId() << endl; |
| 78 | else |
| 79 | cout << "<none>" << endl; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 80 | |
| 81 | cout << "forwardingFlags:"; |
| 82 | if (forwardingEntry.getForwardingFlags().getActive()) |
| 83 | cout << " active"; |
| 84 | if (forwardingEntry.getForwardingFlags().getChildInherit()) |
| 85 | cout << " childInherit"; |
| 86 | if (forwardingEntry.getForwardingFlags().getAdvertise()) |
| 87 | cout << " advertise"; |
| 88 | if (forwardingEntry.getForwardingFlags().getLast()) |
| 89 | cout << " last"; |
| 90 | if (forwardingEntry.getForwardingFlags().getCapture()) |
| 91 | cout << " capture"; |
| 92 | if (forwardingEntry.getForwardingFlags().getLocal()) |
| 93 | cout << " local"; |
| 94 | if (forwardingEntry.getForwardingFlags().getTap()) |
| 95 | cout << " tap"; |
| 96 | if (forwardingEntry.getForwardingFlags().getCaptureOk()) |
| 97 | cout << " captureOk"; |
| 98 | cout << endl; |
| 99 | |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 100 | cout << "freshnessSeconds: "; |
| 101 | if (forwardingEntry.getFreshnessSeconds() >= 0) |
| 102 | cout << forwardingEntry.getFreshnessSeconds() << endl; |
| 103 | else |
| 104 | cout << "<none>" << endl; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Show the interest name and scope, and expect the name to have 4 components where the last component is a data packet |
| 109 | * whose content is a forwarding entry. |
| 110 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 111 | static void dumpInterestWithForwardingEntry(const Interest& interest) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 112 | { |
| 113 | if (interest.getName().getComponentCount() != 4) { |
| 114 | cout << "Error: expected the interest name to have 4 components. Got: " << interest.getName().to_uri() << endl; |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | cout << "scope: "; |
| 119 | if (interest.getScope() >= 0) |
| 120 | cout << interest.getScope() << endl; |
| 121 | else |
| 122 | cout << "<none>" << endl; |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 123 | cout << "name[0]: " << toString(*interest.getName().getComponent(0).getValue()) << endl; |
| 124 | cout << "name[1]: " << toHex(*interest.getName().getComponent(1).getValue()) << endl; |
| 125 | cout << "name[2]: " << toString(*interest.getName().getComponent(2).getValue()) << endl; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 126 | cout << "name[3] decoded as Data, showing content as ForwardingEntry: " << endl; |
| 127 | |
| 128 | Data data; |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 129 | data.wireDecode(*interest.getName().getComponent(3).getValue()); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 130 | |
| 131 | ForwardingEntry forwardingEntry; |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 132 | forwardingEntry.wireDecode(*data.getContent()); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 133 | dumpForwardingEntry(forwardingEntry); |
| 134 | } |
| 135 | |
| 136 | int main(int argc, char** argv) |
| 137 | { |
| 138 | try { |
| 139 | Interest interest; |
| 140 | interest.wireDecode(Interest1, sizeof(Interest1)); |
| 141 | cout << "Interest:" << endl; |
| 142 | dumpInterestWithForwardingEntry(interest); |
| 143 | |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 144 | Blob encoding = interest.wireEncode(); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 145 | cout << endl << "Re-encoded interest " << toHex(*encoding) << endl; |
| 146 | |
| 147 | Interest reDecodedInterest; |
| 148 | reDecodedInterest.wireDecode(*encoding); |
| 149 | cout << "Re-decoded Interest:" << endl; |
| 150 | dumpInterestWithForwardingEntry(reDecodedInterest); |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 151 | } catch (exception& e) { |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 152 | cout << "exception: " << e.what() << endl; |
| 153 | } |
| 154 | return 0; |
| 155 | } |