blob: 1bd15fa702a53352a6a0abde86aa34efaaca735f [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"
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070013#include "forwarding-flags.hpp"
Jeff Thompson990599b2013-08-27 15:14:25 -070014#include "c/forwarding-entry.h"
15
16namespace ndn {
17
18/**
19 * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry.
20 */
21class ForwardingEntry {
22public:
23 ForwardingEntry
Jeff Thompson1656e6a2013-08-29 18:01:48 -070024 (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070025 int faceId, const ForwardingFlags& forwardingFlags, int freshnessSeconds)
Jeff Thompson990599b2013-08-27 15:14:25 -070026 : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest),
27 faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds)
28 {
29 }
30
31 ForwardingEntry()
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070032 : faceId_(-1), freshnessSeconds_(-1)
Jeff Thompson990599b2013-08-27 15:14:25 -070033 {
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070034 forwardingFlags_.setActive(true);
35 forwardingFlags_.setChildInherit(true);
Jeff Thompson990599b2013-08-27 15:14:25 -070036 }
37
Jeff Thompson0050abe2013-09-17 12:50:25 -070038 Blob
39 wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
Jeff Thompson990599b2013-08-27 15:14:25 -070040 {
41 return wireFormat.encodeForwardingEntry(*this);
42 }
Jeff Thompson0050abe2013-09-17 12:50:25 -070043
44 void
Jeff Thompson97223af2013-09-24 17:01:27 -070045 wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070046 {
47 wireFormat.decodeForwardingEntry(*this, input, inputLength);
48 }
Jeff Thompson0050abe2013-09-17 12:50:25 -070049
50 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070051 wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070052 {
53 wireDecode(&input[0], input.size(), wireFormat);
54 }
Jeff Thompson990599b2013-08-27 15:14:25 -070055
56 /**
57 * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
58 * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
59 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
60 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070061 void
62 get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
Jeff Thompson990599b2013-08-27 15:14:25 -070063
Jeff Thompson0050abe2013-09-17 12:50:25 -070064 const std::string&
65 getAction() const { return action_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070066
Jeff Thompson0050abe2013-09-17 12:50:25 -070067 Name&
68 getPrefix() { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070069
Jeff Thompson0050abe2013-09-17 12:50:25 -070070 const Name&
71 getPrefix() const { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070072
Jeff Thompson0050abe2013-09-17 12:50:25 -070073 PublisherPublicKeyDigest&
74 getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
75
76 const PublisherPublicKeyDigest&
77 getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
78
79 int
80 getFaceId() const { return faceId_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070081
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070082 const ForwardingFlags&
Jeff Thompson0050abe2013-09-17 12:50:25 -070083 getForwardingFlags() const { return forwardingFlags_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070084
Jeff Thompson0050abe2013-09-17 12:50:25 -070085 int
86 getFreshnessSeconds() const { return freshnessSeconds_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070087
88 /**
89 * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
90 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
91 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070092 void
93 set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
Jeff Thompson990599b2013-08-27 15:14:25 -070094
Jeff Thompson0050abe2013-09-17 12:50:25 -070095 void
96 setAction(const std::string& value) { action_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -070097
Jeff Thompson0050abe2013-09-17 12:50:25 -070098 void
99 setFaceId(int value) { faceId_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700100
Jeff Thompson0050abe2013-09-17 12:50:25 -0700101 void
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700102 setForwardingFlags(const ForwardingFlags& value) { forwardingFlags_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700103
Jeff Thompson0050abe2013-09-17 12:50:25 -0700104 void
105 setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700106
Jeff Thompson0050abe2013-09-17 12:50:25 -0700107private:
Jeff Thompson990599b2013-08-27 15:14:25 -0700108 std::string action_; /**< empty for none. */
109 Name prefix_;
110 PublisherPublicKeyDigest publisherPublicKeyDigest_;
111 int faceId_; /**< -1 for none. */
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700112 ForwardingFlags forwardingFlags_;
Jeff Thompson990599b2013-08-27 15:14:25 -0700113 int freshnessSeconds_; /**< -1 for none. */
114};
115
116}
117
118#endif