blob: db3f765756f080adb1a98b44e38360b9797c85a0 [file] [log] [blame]
Wentao Shang4d5e1de2014-01-28 21:00:03 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 *
5 * @author: Wentao Shang <wentao@cs.ucla.edu>
6 *
7 * See COPYING for copyright and distribution information.
8 */
9
10#ifndef NDN_FIB_MANAGEMENT_HPP
11#define NDN_FIB_MANAGEMENT_HPP
12
13#include "encoding/block.hpp"
14#include "encoding/tlv-nfd-control.hpp"
15#include "name.hpp"
16
17namespace ndn {
18
19class FibManagementOptions {
20public:
21 FibManagementOptions ()
22 : faceId_ (-1)
23 , cost_ (-1)
24 {
25 }
26
27 const Name&
28 getName () const { return name_; }
29
30 void
31 setName (const Name &name) { name_ = name; wire_.reset (); }
32
33 int
34 getFaceId () const { return faceId_; }
35
36 void
37 setFaceId (int faceId) { faceId_ = faceId; wire_.reset (); }
38
39 int
40 getCost () const { return cost_; }
41
42 void
43 setCost (int cost) { cost_ = cost; wire_.reset (); }
44
45 inline const Block&
46 wireEncode () const;
47
48 inline void
49 wireDecode (const Block &wire);
50
51private:
52 Name name_;
53 int faceId_;
54 int cost_;
55 //Name strategy_;
56 //TODO: implement strategy after its use is properly defined
57
58 mutable Block wire_;
59};
60
61inline const Block&
62FibManagementOptions::wireEncode () const
63{
64 if (wire_.hasWire ())
65 return wire_;
66
67 wire_ = Block (tlv::nfd_control::FibManagementOptions);
68
69 // Name
70 wire_.push_back (name_.wireEncode ());
71
72 // FaceId
73 if (faceId_ != -1)
74 wire_.push_back (nonNegativeIntegerBlock (tlv::nfd_control::FaceId, faceId_));
75
76 // Cost
77 if (cost_ != -1)
78 wire_.push_back (nonNegativeIntegerBlock (tlv::nfd_control::Cost, cost_));
79
80 //TODO: Strategy
81
82 wire_.encode ();
83 return wire_;
84}
85
86inline void
87FibManagementOptions::wireDecode (const Block &wire)
88{
89 name_.clear ();
90 faceId_ = -1;
91 cost_ = -1;
92
93 wire_ = wire;
94 wire_.parse ();
95
96 // Name
97 Block::element_iterator val = wire_.find(Tlv::Name);
98 if (val != wire_.getAll().end())
99 {
100 name_.wireDecode(*val);
101 }
102
103 // FaceID
104 val = wire_.find(tlv::nfd_control::FaceId);
105 if (val != wire_.getAll().end())
106 {
107 faceId_ = readNonNegativeInteger(*val);
108 }
109
110 // Cost
111 val = wire_.find(tlv::nfd_control::Cost);
112 if (val != wire_.getAll().end())
113 {
114 cost_ = readNonNegativeInteger(*val);
115 }
116
117 //TODO: Strategy
118}
119
120inline std::ostream&
121operator << (std::ostream &os, const FibManagementOptions &option)
122{
123 os << "ForwardingEntry(";
124
125 // Name
126 os << "Prefix: " << option.getName () << ", ";
127
128 // FaceID
129 os << "FaceID: " << option.getFaceId () << ", ";
130
131 // Cost
132 os << "Cost: " << option.getCost ();
133
134 os << ")";
135 return os;
136}
137
138}
139
140#endif