-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnfdc-helpers.h
147 lines (126 loc) · 4.65 KB
/
nfdc-helpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// AUTHOR: Zhiyi Zhang
// EMAIL: zhiyi@cs.ucla.edu
// License: LGPL v3.0
#include "nfd-command-tlv.h"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/security/command-interest-signer.hpp>
#include <iostream>
namespace ndn {
namespace ndnd {
static Block
make_rib_unregeister_interest_parameter(const Name& route_name, int face_id)
{
auto block = makeEmptyBlock(CONTROL_PARAMETERS);
Block route_name_block = route_name.wireEncode();
Block face_id_block = makeNonNegativeIntegerBlock(FACE_ID, face_id);
Block origin_block = makeNonNegativeIntegerBlock(ORIGIN, 0xFF);
block.push_back(route_name_block);
block.push_back(face_id_block);
block.push_back(origin_block);
std::cerr << "Route name block:" << std::endl;
std::cerr << route_name_block << std::endl;
std::cerr << "Face id block:" << std::endl;
std::cerr << face_id_block << std::endl;
std::cerr << "Control parameters block:" << std::endl;
std::cerr << block << std::endl;
block.encode();
return block;
}
static Block
make_rib_interest_parameter(const Name& route_name, int face_id)
{
auto block = makeEmptyBlock(CONTROL_PARAMETERS);
Block route_name_block = route_name.wireEncode();
Block face_id_block = makeNonNegativeIntegerBlock(FACE_ID, face_id);
Block origin_block = makeNonNegativeIntegerBlock(ORIGIN, 0xFF);
Block cost_block = makeNonNegativeIntegerBlock(COST, 0);
Block flags_block = makeNonNegativeIntegerBlock(FLAGS, 0x01);
block.push_back(route_name_block);
block.push_back(face_id_block);
block.push_back(origin_block);
block.push_back(cost_block);
block.push_back(flags_block);
std::cerr << "Route name block:" << std::endl;
std::cerr << route_name_block << std::endl;
std::cerr << "Face id block:" << std::endl;
std::cerr << face_id_block << std::endl;
std::cerr << "Control parameters block:" << std::endl;
std::cerr << block << std::endl;
block.encode();
return block;
}
static Interest
prepareRibUnregisterInterest(const Name& route_name, int face_id, KeyChain& keychain,
int cost = 0)
{
Name name("/localhost/nfd/rib/unregister");
Block control_params = make_rib_unregeister_interest_parameter(route_name, face_id);
name.append(control_params);
security::CommandInterestSigner signer(keychain);
Interest interest = signer.makeCommandInterest(name);
interest.setMustBeFresh(true);
interest.setCanBePrefix(false);
return interest;
}
static Interest
prepareRibRegisterInterest(const Name& route_name, int face_id, KeyChain& keychain,
int cost = 0)
{
Name name("/localhost/nfd/rib/register");
Block control_params = make_rib_interest_parameter(route_name, face_id);
name.append(control_params);
security::CommandInterestSigner signer(keychain);
Interest interest = signer.makeCommandInterest(name);
interest.setMustBeFresh(true);
interest.setCanBePrefix(false);
return interest;
}
static Interest
prepareFaceCreationInterest(const std::string& uri, KeyChain& keychain)
{
Name name("/localhost/nfd/faces/create");
auto control_block = makeEmptyBlock(CONTROL_PARAMETERS);
control_block.push_back(makeStringBlock(URI, uri));
control_block.encode();
name.append(control_block);
security::CommandInterestSigner signer(keychain);
Interest interest = signer.makeCommandInterest(name);
interest.setMustBeFresh(true);
interest.setCanBePrefix(false);
return interest;
}
static Interest
prepareFaceDestroyInterest(int face_id, KeyChain& keychain)
{
Name name("/localhost/nfd/faces/destroy");
auto control_block = makeEmptyBlock(CONTROL_PARAMETERS);
control_block.push_back(makeNonNegativeIntegerBlock(FACE_ID, face_id));
control_block.encode();
name.append(control_block);
security::CommandInterestSigner signer(keychain);
Interest interest = signer.makeCommandInterest(name);
interest.setMustBeFresh(true);
interest.setCanBePrefix(false);
return interest;
}
static Interest
prepareStrategySetInterest(const std::string& prefix, const std::string& strategy,
KeyChain& keychain) {
Name name("/localhost/nfd/strategy-choice/set");
auto prefix_block = Name(prefix).wireEncode();
auto strategy_block = makeEmptyBlock(STRATEGY);
strategy_block.push_back(Name(strategy).wireEncode());
auto control_block = makeEmptyBlock(CONTROL_PARAMETERS);
control_block.push_back(prefix_block);
control_block.push_back(strategy_block);
control_block.encode();
name.append(control_block);
security::CommandInterestSigner signer(keychain);
Interest interest = signer.makeCommandInterest(name);
interest.setMustBeFresh(true);
interest.setCanBePrefix(false);
return interest;
}
} // namespace ndnd
} // namespace ndn