blob: 152b79f0a588d76dc53d75fb3445c2b31a559e39 [file] [log] [blame]
Jeff Thompson990599b2013-08-27 15:14:25 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson990599b2013-08-27 15:14:25 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#include <cstdlib>
8#include <sstream>
9#include <iostream>
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"
14
15using namespace std;
16using namespace ndn;
17
Jeff Thompson10ad12a2013-09-24 16:19:11 -070018uint8_t Interest1[] = {
Jeff Thompson990599b2013-08-27 15:14:25 -0700190x01, 0xd2, 0xf2, 0xfa, 0xa5, 0x6e, 0x64, 0x6e, 0x78, 0x00, 0xfa, 0x02, 0x85, 0xe0, 0xa0, 0x1e, 0x09, 0x39, 0x68,
200xf9, 0x74, 0x0c, 0xe7, 0xf4, 0x36, 0x1b, 0xab, 0xf5, 0xbb, 0x05, 0xa4, 0xe5, 0x5a, 0xac, 0xa5, 0xe5, 0x8f, 0x73,
210xed, 0xde, 0xb8, 0xe0, 0x13, 0xaa, 0x8f, 0x00, 0xfa, 0xcd, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x72, 0x65, 0x67,
220x00, 0xfa, 0x29, 0xad, 0x04, 0x82, 0x02, 0xaa, 0x03, 0xb2, 0x08, 0x85, 0x4d, 0xdb, 0xf6, 0x97, 0x79, 0xcd, 0xf4,
230xef, 0x74, 0xbe, 0x99, 0x47, 0x44, 0x78, 0xc8, 0xbc, 0x3c, 0xa0, 0x87, 0x3e, 0x0f, 0xfa, 0x1f, 0xa6, 0x01, 0x20,
240xaa, 0x27, 0x6d, 0xb1, 0x22, 0xb8, 0x34, 0x04, 0xe5, 0x95, 0xa8, 0xa3, 0xca, 0xea, 0xf0, 0x96, 0x30, 0x27, 0x66,
250x58, 0xba, 0x4e, 0x7b, 0xea, 0xad, 0xb4, 0xb9, 0x1a, 0x8c, 0xc5, 0x8e, 0x19, 0xac, 0x4a, 0x42, 0x28, 0x95, 0x07,
260xed, 0x8d, 0x60, 0x9a, 0xa9, 0xbe, 0xf6, 0x1a, 0x5a, 0x50, 0x7f, 0x34, 0x9c, 0x83, 0xd2, 0x94, 0x4b, 0x8c, 0x16,
270xfe, 0xcf, 0xd9, 0x0d, 0x4a, 0x40, 0xdd, 0xb8, 0x68, 0x75, 0x92, 0xc0, 0xa5, 0x75, 0x17, 0x56, 0x42, 0x35, 0xb2,
280xe3, 0x59, 0xdb, 0x54, 0xf5, 0x1a, 0x37, 0xe1, 0xac, 0x39, 0xe5, 0x18, 0xa2, 0x19, 0x6e, 0x3f, 0xfd, 0xa7, 0xeb,
290x2f, 0xb3, 0x01, 0xf3, 0xc4, 0x04, 0xdd, 0x00, 0x00, 0xf2, 0x00, 0x01, 0xa2, 0x03, 0xe2, 0x02, 0x85, 0xef, 0x7c,
300x4f, 0x5d, 0x47, 0x43, 0xa8, 0xb8, 0x58, 0x6e, 0xa2, 0xe7, 0x41, 0xb7, 0xfc, 0x39, 0xd1, 0xdc, 0x0d, 0xbe, 0x1b,
310x19, 0x30, 0xe7, 0x87, 0xcf, 0xd1, 0xd8, 0x33, 0xea, 0x7a, 0x61, 0x00, 0x02, 0xba, 0xb5, 0x04, 0xfc, 0xe9, 0xe2,
320x53, 0xd7, 0x00, 0x01, 0xe2, 0x01, 0x82, 0x19, 0xfd, 0x30, 0x82, 0x01, 0x9b, 0x30, 0x82, 0x01, 0x04, 0x02, 0x09,
330x00, 0xb7, 0xd8, 0x5c, 0x90, 0x6b, 0xad, 0x52, 0xee, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
340x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, 0x61,
350x78, 0x65, 0x6c, 0x63, 0x64, 0x76, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x32, 0x30, 0x34, 0x32, 0x38, 0x32, 0x33, 0x34,
360x34, 0x33, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x32, 0x30, 0x35, 0x32, 0x38, 0x32, 0x33, 0x34, 0x34, 0x33, 0x37, 0x5a,
370x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, 0x61, 0x78, 0x65, 0x6c, 0x63, 0x64,
380x76, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
390x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xe1, 0x7d, 0x30, 0xa7, 0xd8, 0x28, 0xab, 0x1b,
400x84, 0x0b, 0x17, 0x54, 0x2d, 0xca, 0xf6, 0x20, 0x7a, 0xfd, 0x22, 0x1e, 0x08, 0x6b, 0x2a, 0x60, 0xd1, 0x6c, 0xb7,
410xf5, 0x44, 0x48, 0xba, 0x9f, 0x3f, 0x08, 0xbc, 0xd0, 0x99, 0xdb, 0x21, 0xdd, 0x16, 0x2a, 0x77, 0x9e, 0x61, 0xaa,
420x89, 0xee, 0xe5, 0x54, 0xd3, 0xa4, 0x7d, 0xe2, 0x30, 0xbc, 0x7a, 0xc5, 0x90, 0xd5, 0x24, 0x06, 0x7c, 0x38, 0x98,
430xbb, 0xa6, 0xf5, 0xdc, 0x43, 0x60, 0xb8, 0x45, 0xed, 0xa4, 0x8c, 0xbd, 0x9c, 0xf1, 0x26, 0xa7, 0x23, 0x44, 0x5f,
440x0e, 0x19, 0x52, 0xd7, 0x32, 0x5a, 0x75, 0xfa, 0xf5, 0x56, 0x14, 0x4f, 0x9a, 0x98, 0xaf, 0x71, 0x86, 0xb0, 0x27,
450x86, 0x85, 0xb8, 0xe2, 0xc0, 0x8b, 0xea, 0x87, 0x17, 0x1b, 0x4d, 0xee, 0x58, 0x5c, 0x18, 0x28, 0x29, 0x5b, 0x53,
460x95, 0xeb, 0x4a, 0x17, 0x77, 0x9f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
470xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0xcb, 0x3a, 0xb0, 0x35, 0x7d, 0x7c, 0xd2, 0xae,
480x97, 0xed, 0x50, 0x1e, 0x51, 0xa3, 0xa0, 0xe2, 0x81, 0x7d, 0x41, 0x8e, 0x47, 0xfb, 0x17, 0x90, 0x64, 0x77, 0xaf,
490x61, 0x49, 0x5a, 0x7e, 0x8d, 0x87, 0x89, 0x14, 0x10, 0x65, 0xb0, 0x82, 0xd0, 0x01, 0xf4, 0xb1, 0x51, 0x93, 0xd0,
500xb4, 0x3f, 0xb6, 0x61, 0xcd, 0xe2, 0x0a, 0x64, 0x98, 0x37, 0x2c, 0x6a, 0xbb, 0xd3, 0xdc, 0xb9, 0xf0, 0xd1, 0x26,
510x59, 0xef, 0x07, 0xb3, 0xc6, 0xdb, 0xdf, 0x8b, 0xdf, 0x2f, 0x65, 0x47, 0x7e, 0xed, 0x7a, 0xdc, 0xd4, 0x57, 0xd7,
520x93, 0xb1, 0xc2, 0x7b, 0xad, 0xda, 0x7c, 0x5a, 0xde, 0x80, 0xce, 0x95, 0xb7, 0xd8, 0x82, 0x7f, 0xe7, 0x8c, 0x8a,
530x35, 0xf3, 0xfb, 0x4b, 0xa6, 0x48, 0xa0, 0x81, 0xbe, 0x2c, 0xfe, 0x84, 0x23, 0x1a, 0xba, 0xb3, 0xc2, 0xb5, 0x31,
540x74, 0x6d, 0xf2, 0xe0, 0x49, 0x2b, 0x00, 0x00, 0x00, 0x01, 0x9a, 0x02, 0xd5, 0x05, 0x8a, 0x04, 0xca, 0xbe, 0x73,
550x65, 0x6c, 0x66, 0x72, 0x65, 0x67, 0x00, 0xf2, 0xfa, 0xa5, 0x6d, 0x65, 0x6b, 0x69, 0x00, 0x00, 0x04, 0xfa, 0x8e,
560x33, 0x00, 0x03, 0xd2, 0xd6, 0x32, 0x31, 0x34, 0x37, 0x34, 0x38, 0x33, 0x36, 0x34, 0x37, 0x00, 0x00, 0x00, 0x00,
570x00, 0x00, 0x02, 0xd2, 0x8e, 0x31, 0x00, 0x00,
581
59};
60
Jeff Thompson10ad12a2013-09-24 16:19:11 -070061static inline string toString(const vector<uint8_t>& v)
Jeff Thompson990599b2013-08-27 15:14:25 -070062{
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070063 if (!&v)
64 return "";
65
Jeff Thompson990599b2013-08-27 15:14:25 -070066 return string(&v[0], &v[0] + v.size());
67}
68
Jeff Thompson1656e6a2013-08-29 18:01:48 -070069static void dumpForwardingEntry(const ForwardingEntry& forwardingEntry)
Jeff Thompson990599b2013-08-27 15:14:25 -070070{
71 cout << "action: " << forwardingEntry.getAction() << endl;
72 cout << "prefix: " << forwardingEntry.getPrefix().to_uri() << endl;
73 cout << "publisherPublicKeyDigest: "
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070074 << (forwardingEntry.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ? toHex(*forwardingEntry.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()) : "<none>") << endl;
Jeff Thompson990599b2013-08-27 15:14:25 -070075 cout << "faceId: ";
76 if (forwardingEntry.getFaceId() >= 0)
77 cout << forwardingEntry.getFaceId() << endl;
78 else
79 cout << "<none>" << endl;
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070080
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 Thompson990599b2013-08-27 15:14:25 -0700100 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 Thompson1656e6a2013-08-29 18:01:48 -0700111static void dumpInterestWithForwardingEntry(const Interest& interest)
Jeff Thompson990599b2013-08-27 15:14:25 -0700112{
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 Thompsonc2b7b142013-09-12 15:29:04 -0700123 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 Thompson990599b2013-08-27 15:14:25 -0700126 cout << "name[3] decoded as Data, showing content as ForwardingEntry: " << endl;
127
128 Data data;
Jeff Thompsonc2b7b142013-09-12 15:29:04 -0700129 data.wireDecode(*interest.getName().getComponent(3).getValue());
Jeff Thompson990599b2013-08-27 15:14:25 -0700130
131 ForwardingEntry forwardingEntry;
Jeff Thompsonc2b7b142013-09-12 15:29:04 -0700132 forwardingEntry.wireDecode(*data.getContent());
Jeff Thompson990599b2013-08-27 15:14:25 -0700133 dumpForwardingEntry(forwardingEntry);
134}
135
136int 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 Thompsonc2b7b142013-09-12 15:29:04 -0700144 Blob encoding = interest.wireEncode();
Jeff Thompson990599b2013-08-27 15:14:25 -0700145 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 Thompson1656e6a2013-08-29 18:01:48 -0700151 } catch (exception& e) {
Jeff Thompson990599b2013-08-27 15:14:25 -0700152 cout << "exception: " << e.what() << endl;
153 }
154 return 0;
155}