blob: 3c88a89af6b42f220a6956c921a6357e6806e231 [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#ifndef NDN_FORWARDING_ENTRY_HPP
8#define NDN_FORWARDING_ENTRY_HPP
9
10#include <string>
11#include "name.hpp"
12#include "publisher-public-key-digest.hpp"
13#include "c/forwarding-entry.h"
14
15namespace ndn {
16
17/**
18 * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry.
19 */
20class ForwardingEntry {
21public:
22 ForwardingEntry
Jeff Thompson1656e6a2013-08-29 18:01:48 -070023 (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
Jeff Thompson990599b2013-08-27 15:14:25 -070024 int faceId, int forwardingFlags, int freshnessSeconds)
25 : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest),
26 faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds)
27 {
28 }
29
30 ForwardingEntry()
31 : faceId_(-1), forwardingFlags_(-1), freshnessSeconds_(-1)
32 {
33 }
34
Jeff Thompson0050abe2013-09-17 12:50:25 -070035 Blob
36 wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
Jeff Thompson990599b2013-08-27 15:14:25 -070037 {
38 return wireFormat.encodeForwardingEntry(*this);
39 }
Jeff Thompson0050abe2013-09-17 12:50:25 -070040
41 void
42 wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070043 {
44 wireFormat.decodeForwardingEntry(*this, input, inputLength);
45 }
Jeff Thompson0050abe2013-09-17 12:50:25 -070046
47 void
48 wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070049 {
50 wireDecode(&input[0], input.size(), wireFormat);
51 }
Jeff Thompson990599b2013-08-27 15:14:25 -070052
53 /**
54 * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
55 * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
56 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
57 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070058 void
59 get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
Jeff Thompson990599b2013-08-27 15:14:25 -070060
Jeff Thompson0050abe2013-09-17 12:50:25 -070061 const std::string&
62 getAction() const { return action_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070063
Jeff Thompson0050abe2013-09-17 12:50:25 -070064 Name&
65 getPrefix() { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070066
Jeff Thompson0050abe2013-09-17 12:50:25 -070067 const Name&
68 getPrefix() const { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070069
Jeff Thompson0050abe2013-09-17 12:50:25 -070070 PublisherPublicKeyDigest&
71 getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
72
73 const PublisherPublicKeyDigest&
74 getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
75
76 int
77 getFaceId() const { return faceId_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070078
Jeff Thompson0050abe2013-09-17 12:50:25 -070079 int
80 getForwardingFlags() const { return forwardingFlags_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070081
Jeff Thompson0050abe2013-09-17 12:50:25 -070082 int
83 getFreshnessSeconds() const { return freshnessSeconds_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070084
85 /**
86 * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
87 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
88 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070089 void
90 set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
Jeff Thompson990599b2013-08-27 15:14:25 -070091
Jeff Thompson0050abe2013-09-17 12:50:25 -070092 void
93 setAction(const std::string& value) { action_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -070094
Jeff Thompson0050abe2013-09-17 12:50:25 -070095 void
96 setFaceId(int value) { faceId_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -070097
Jeff Thompson0050abe2013-09-17 12:50:25 -070098 void
99 setForwardingFlags(int value) { forwardingFlags_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700100
Jeff Thompson0050abe2013-09-17 12:50:25 -0700101 void
102 setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700103
Jeff Thompson0050abe2013-09-17 12:50:25 -0700104private:
Jeff Thompson990599b2013-08-27 15:14:25 -0700105 std::string action_; /**< empty for none. */
106 Name prefix_;
107 PublisherPublicKeyDigest publisherPublicKeyDigest_;
108 int faceId_; /**< -1 for none. */
109 int forwardingFlags_; /**< -1 for none. */
110 int freshnessSeconds_; /**< -1 for none. */
111};
112
113}
114
115#endif