blob: 675b56b04b76f57bc9e166c799b2d8e8e5a0797f [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson990599b2013-08-27 15:14:25 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson990599b2013-08-27 15:14:25 -07005 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_FORWARDING_ENTRY_HPP
9#define NDN_FORWARDING_ENTRY_HPP
10
11#include <string>
12#include "name.hpp"
13#include "publisher-public-key-digest.hpp"
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070014#include "forwarding-flags.hpp"
Jeff Thompson25b4e612013-10-10 16:03:24 -070015#include "encoding/wire-format.hpp"
16
17struct ndn_ForwardingEntry;
Jeff Thompson990599b2013-08-27 15:14:25 -070018
19namespace ndn {
20
21/**
22 * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry.
23 */
24class ForwardingEntry {
25public:
26 ForwardingEntry
Jeff Thompson1656e6a2013-08-29 18:01:48 -070027 (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070028 int faceId, const ForwardingFlags& forwardingFlags, int freshnessSeconds)
Jeff Thompson990599b2013-08-27 15:14:25 -070029 : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest),
30 faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds)
31 {
32 }
33
34 ForwardingEntry()
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070035 : faceId_(-1), freshnessSeconds_(-1)
Jeff Thompson990599b2013-08-27 15:14:25 -070036 {
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070037 forwardingFlags_.setActive(true);
38 forwardingFlags_.setChildInherit(true);
Jeff Thompson990599b2013-08-27 15:14:25 -070039 }
40
Jeff Thompson0050abe2013-09-17 12:50:25 -070041 Blob
42 wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
Jeff Thompson990599b2013-08-27 15:14:25 -070043 {
44 return wireFormat.encodeForwardingEntry(*this);
45 }
Jeff Thompson0050abe2013-09-17 12:50:25 -070046
47 void
Jeff Thompson97223af2013-09-24 17:01:27 -070048 wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070049 {
50 wireFormat.decodeForwardingEntry(*this, input, inputLength);
51 }
Jeff Thompson0050abe2013-09-17 12:50:25 -070052
53 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070054 wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070055 {
56 wireDecode(&input[0], input.size(), wireFormat);
57 }
Jeff Thompson990599b2013-08-27 15:14:25 -070058
59 /**
60 * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
61 * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
62 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
63 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070064 void
65 get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
Jeff Thompson990599b2013-08-27 15:14:25 -070066
Jeff Thompson0050abe2013-09-17 12:50:25 -070067 const std::string&
68 getAction() const { return action_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070069
Jeff Thompson0050abe2013-09-17 12:50:25 -070070 Name&
71 getPrefix() { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070072
Jeff Thompson0050abe2013-09-17 12:50:25 -070073 const Name&
74 getPrefix() const { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070075
Jeff Thompson0050abe2013-09-17 12:50:25 -070076 PublisherPublicKeyDigest&
77 getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
78
79 const PublisherPublicKeyDigest&
80 getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
81
82 int
83 getFaceId() const { return faceId_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070084
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070085 const ForwardingFlags&
Jeff Thompson0050abe2013-09-17 12:50:25 -070086 getForwardingFlags() const { return forwardingFlags_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070087
Jeff Thompson0050abe2013-09-17 12:50:25 -070088 int
89 getFreshnessSeconds() const { return freshnessSeconds_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070090
91 /**
92 * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
93 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
94 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070095 void
96 set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
Jeff Thompson990599b2013-08-27 15:14:25 -070097
Jeff Thompson0050abe2013-09-17 12:50:25 -070098 void
99 setAction(const std::string& value) { action_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700100
Jeff Thompson0050abe2013-09-17 12:50:25 -0700101 void
102 setFaceId(int value) { faceId_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700103
Jeff Thompson0050abe2013-09-17 12:50:25 -0700104 void
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700105 setForwardingFlags(const ForwardingFlags& value) { forwardingFlags_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700106
Jeff Thompson0050abe2013-09-17 12:50:25 -0700107 void
108 setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -0700109
Jeff Thompson0050abe2013-09-17 12:50:25 -0700110private:
Jeff Thompson990599b2013-08-27 15:14:25 -0700111 std::string action_; /**< empty for none. */
112 Name prefix_;
113 PublisherPublicKeyDigest publisherPublicKeyDigest_;
114 int faceId_; /**< -1 for none. */
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700115 ForwardingFlags forwardingFlags_;
Jeff Thompson990599b2013-08-27 15:14:25 -0700116 int freshnessSeconds_; /**< -1 for none. */
117};
118
119}
120
121#endif