blob: fc2fe6d10444084499bf3e64cfd142d07486ac41 [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 Thompsonc2b7b142013-09-12 15:29:04 -070035 Blob wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
Jeff Thompson990599b2013-08-27 15:14:25 -070036 {
37 return wireFormat.encodeForwardingEntry(*this);
38 }
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070039 void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070040 {
41 wireFormat.decodeForwardingEntry(*this, input, inputLength);
42 }
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070043 void wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070044 {
45 wireDecode(&input[0], input.size(), wireFormat);
46 }
Jeff Thompson990599b2013-08-27 15:14:25 -070047
48 /**
49 * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
50 * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
51 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
52 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070053 void get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
Jeff Thompson990599b2013-08-27 15:14:25 -070054
Jeff Thompson1656e6a2013-08-29 18:01:48 -070055 const std::string& getAction() const { return action_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070056
Jeff Thompson1656e6a2013-08-29 18:01:48 -070057 Name& getPrefix() { return prefix_; }
58 const Name& getPrefix() const { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070059
Jeff Thompson1656e6a2013-08-29 18:01:48 -070060 PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
61 const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070062
63 int getFaceId() const { return faceId_; }
64
65 int getForwardingFlags() const { return forwardingFlags_; }
66
67 int getFreshnessSeconds() const { return freshnessSeconds_; }
68
69 /**
70 * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
71 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
72 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070073 void set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
Jeff Thompson990599b2013-08-27 15:14:25 -070074
Jeff Thompson1656e6a2013-08-29 18:01:48 -070075 void setAction(const std::string& value) { action_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -070076
77 void setFaceId(int value) { faceId_ = value; }
78
79 void setForwardingFlags(int value) { forwardingFlags_ = value; }
80
81 void setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
82
83 std::string action_; /**< empty for none. */
84 Name prefix_;
85 PublisherPublicKeyDigest publisherPublicKeyDigest_;
86 int faceId_; /**< -1 for none. */
87 int forwardingFlags_; /**< -1 for none. */
88 int freshnessSeconds_; /**< -1 for none. */
89};
90
91}
92
93#endif