blob: 53862e18f3110e86cac9b8478817286bc12ee0d8 [file] [log] [blame]
Wentao Shangbd63e462012-12-03 16:19:33 -08001/**
Jeff Thompson146d7de2012-11-17 16:15:28 -08002 * @author: Meki Cheraoui
Jeff Thompson745026e2012-10-13 12:49:20 -07003 * See COPYING for copyright and distribution information.
Meki Cherkaouif3d8f692012-05-18 15:44:28 -07004 * This class represents Forwarding Entries
5 */
Meki Cherkaouiabb973b2012-05-09 14:25:57 -07006
Jeff Thompson2b14c7e2013-07-29 15:09:56 -07007/**
8 * Create a new ForwardingEntry with the optional arguments.
9 * @constructor
10 * @param {String} action
11 * @param {Name} prefixName
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070012 * @param {PublisherPublicKeyDigest} ndndId
Jeff Thompson2b14c7e2013-07-29 15:09:56 -070013 * @param {number} faceID
14 * @param {number} flags
15 * @param {number} lifetime in seconds
16 */
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070017var ForwardingEntry = function ForwardingEntry(action, prefixName, ndndId, faceID, flags, lifetime) {
Jeff Thompson2b14c7e2013-07-29 15:09:56 -070018 this.action = action;
19 this.prefixName = prefixName;
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070020 this.ndndID = ndndId;
Jeff Thompson2b14c7e2013-07-29 15:09:56 -070021 this.faceID = faceID;
22 this.flags = flags;
23 this.lifetime = lifetime;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070024};
25
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070026ForwardingEntry.prototype.from_ndnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070027 //XMLDecoder
28 decoder)
29 //throws ContentDecodingException
30 {
31 decoder.readStartElement(this.getElementLabel());
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070032 if (decoder.peekStartElement(NDNProtocolDTags.Action)) {
33 this.action = decoder.readUTF8Element(NDNProtocolDTags.Action);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070034 }
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070035 if (decoder.peekStartElement(NDNProtocolDTags.Name)) {
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070036 this.prefixName = new Name();
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070037 this.prefixName.from_ndnb(decoder) ;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070038 }
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070039 if (decoder.peekStartElement(NDNProtocolDTags.PublisherPublicKeyDigest)) {
40 this.NdndId = new PublisherPublicKeyDigest();
41 this.NdndId.from_ndnb(decoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070042 }
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070043 if (decoder.peekStartElement(NDNProtocolDTags.FaceID)) {
44 this.faceID = decoder.readIntegerElement(NDNProtocolDTags.FaceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070045 }
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070046 if (decoder.peekStartElement(NDNProtocolDTags.ForwardingFlags)) {
47 this.flags = decoder.readIntegerElement(NDNProtocolDTags.ForwardingFlags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070048 }
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070049 if (decoder.peekStartElement(NDNProtocolDTags.FreshnessSeconds)) {
50 this.lifetime = decoder.readIntegerElement(NDNProtocolDTags.FreshnessSeconds);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070051 }
52 decoder.readEndElement();
53 };
54
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070055ForwardingEntry.prototype.to_ndnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070056 //XMLEncoder
57encoder)
58{
59
60
61 //if (!validate()) {
62 //throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
63 //}
64 encoder.writeStartElement(this.getElementLabel());
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070065 if (null != this.action && this.action.length != 0)
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070066 encoder.writeElement(NDNProtocolDTags.Action, this.action);
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070067 if (null != this.prefixName) {
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070068 this.prefixName.to_ndnb(encoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070069 }
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070070 if (null != this.NdndId) {
71 this.NdndId.to_ndnb(encoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070072 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070073 if (null != this.faceID) {
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070074 encoder.writeElement(NDNProtocolDTags.FaceID, this.faceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070075 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070076 if (null != this.flags) {
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070077 encoder.writeElement(NDNProtocolDTags.ForwardingFlags, this.flags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070078 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070079 if (null != this.lifetime) {
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070080 encoder.writeElement(NDNProtocolDTags.FreshnessSeconds, this.lifetime);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070081 }
82 encoder.writeEndElement();
83 };
84
Alexander Afanasyev03d3f742013-08-14 17:47:28 -070085ForwardingEntry.prototype.getElementLabel = function() { return NDNProtocolDTags.ForwardingEntry; }