diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/Makefile.in ns/Makefile.in --- ns-allinone-2.1b7a/ns-2.1b7a/Makefile.in Wed Oct 18 22:10:22 2000 +++ ns/Makefile.in Thu Mar 1 17:16:24 2001 @@ -95,6 +95,10 @@ # WIN32: uncomment the following line to include specific make for VC++ # !include +OLSR_OBJS = olsr/olsr.o olsr/packet.o olsr/neighbor.o \ + olsr/mprselector.o olsr/duptable.o olsr/topology.o \ + olsr/mpr2.o olsr/ns-olsragent.o + OBJ_CC = \ random.o rng.o ranvar.o misc.o timer-handler.o \ scheduler.o object.o \ @@ -166,6 +170,7 @@ linkstate/hdr-ls.o \ mpls/classifier-addr-mpls.o mpls/ldp.o mpls/mpls-module.o \ rtmodule.o classifier-hier.o addr-params.o \ + $(OLSR_OBJS) \ $(OBJ_STL) # don't allow comments to follow continuation lines diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/antenna.cc ns/antenna.cc --- ns-allinone-2.1b7a/ns-2.1b7a/antenna.cc Mon Jan 4 20:45:02 1999 +++ ns/antenna.cc Tue Mar 27 13:21:56 2001 @@ -38,6 +38,8 @@ $Id: antenna.cc,v 1.2 1999/01/04 19:45:02 haldar Exp $ */ +#include + #include static class AntennaClass : public TclClass { @@ -55,7 +57,6 @@ bind("Y_", &Y_); bind("Z_", &Z_); } - double Antenna::getTxGain(double /*dX*/, double /*dY*/, double /*dZ*/, diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/antenna.h ns/antenna.h --- ns-allinone-2.1b7a/ns-2.1b7a/antenna.h Thu Aug 17 02:03:38 2000 +++ ns/antenna.h Tue Mar 27 13:21:56 2001 @@ -89,4 +89,6 @@ }; + + #endif // ns_antenna_h diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/aodv/aodv.cc ns/aodv/aodv.cc --- ns-allinone-2.1b7a/ns-2.1b7a/aodv/aodv.cc Fri Sep 1 05:04:08 2000 +++ ns/aodv/aodv.cc Tue Jun 26 15:41:38 2001 @@ -1201,15 +1201,16 @@ void AODV::sendRequest(nsaddr_t dst) { -Node *thisnode = Node::get_node_by_address(index); -// Allocate a RREQ packet -Packet *p = Packet::alloc(); -struct hdr_cmn *ch = HDR_CMN(p); -struct hdr_ip *ih = HDR_IP(p); -struct hdr_aodv_request *rq = HDR_AODV_REQUEST(p); -rt_entry *rt = rtable.rt_lookup(dst); + Node *thisnode = Node::get_node_by_address(index); + // Allocate a RREQ packet + Packet *p = Packet::alloc(); + struct hdr_cmn *ch = HDR_CMN(p); + struct hdr_ip *ih = HDR_IP(p); + struct hdr_aodv_request *rq = HDR_AODV_REQUEST(p); + rt_entry *rt = rtable.rt_lookup(dst); - assert(rt); + if (rt == 0) + rt = rtable.rt_add(dst); /* * Rate limit sending of Route Requests. We are very conservative diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/aodv/aodv.h ns/aodv/aodv.h --- ns-allinone-2.1b7a/ns-2.1b7a/aodv/aodv.h Fri Sep 1 05:04:08 2000 +++ ns/aodv/aodv.h Tue Jun 26 14:22:42 2001 @@ -90,7 +90,7 @@ * it. */ -#define AODV_LINK_LAYER_DETECTION +//#define AODV_LINK_LAYER_DETECTION /* * Allows AODV to use link-layer (802.11) feedback in determining when Only in ns-allinone-2.1b7a/ns-2.1b7a: autoconf.h diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/cmu-trace.cc ns/cmu-trace.cc --- ns-allinone-2.1b7a/ns-2.1b7a/cmu-trace.cc Fri Sep 1 05:04:05 2000 +++ ns/cmu-trace.cc Thu Mar 1 17:16:25 2001 @@ -49,6 +49,7 @@ #include //TORA #include // IMEP #include //AODV +#include // OLSR #include #include @@ -313,6 +314,15 @@ srh->down_links()[srh->num_route_errors() - 1].to_addr); } +void CMUTrace::format_olsr(Packet *p, int offset){ + uint8_t *data = (uint8_t*)p->accessdata(); + int packet_size = p->datalen(); + olsr_packet pck(data, packet_size); + sprintf(wrk_ + offset, + "-P olsr -Pl %d", + pck.length()); +} + void CMUTrace::format_msg(Packet *, int) { @@ -726,6 +736,9 @@ break; case PT_DSR: format_dsr(p, offset); + break; + case PT_OLSR: + format_olsr(p, offset); break; case PT_MESSAGE: case PT_UDP: diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/cmu-trace.h ns/cmu-trace.h --- ns-allinone-2.1b7a/ns-2.1b7a/cmu-trace.h Fri Sep 1 05:04:05 2000 +++ ns/cmu-trace.h Thu Mar 1 17:22:57 2001 @@ -112,6 +112,7 @@ void format_tora(Packet *p, int offset); void format_imep(Packet *p, int offset); void format_aodv(Packet *p, int offset); + void format_olsr(Packet *p, int offset); }; #endif /* __cmu_trace__ */ Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: app-dataflow.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: appdata-hier.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: cache-flowchart.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: hier-classifier.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: link.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: mcastNode.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: mpath.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: ndactions.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: node.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: pagepool-hier.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: rtarch.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: rtlconfig.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: rtmodule.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: sessionArch.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: srmhierarchy.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: tclclass-runt.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: tclclass-static.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: tclclass.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: tclobject-cmd.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: tclobject-hier.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: tclobject-mech.obj Only in ns-allinone-2.1b7a/ns-2.1b7a/doc/figures: uni-nd-intf.obj Only in ns-allinone-2.1b7a/ns-2.1b7a: gen diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/god.cc ns/god.cc --- ns-allinone-2.1b7a/ns-2.1b7a/god.cc Wed Oct 18 22:10:23 2000 +++ ns/god.cc Fri Mar 2 10:30:16 2001 @@ -468,9 +468,9 @@ return false; } - vector a(mb_node[i]->X(), mb_node[i]->Y(), mb_node[i]->Z()); - vector b(mb_node[j]->X(), mb_node[j]->Y(), mb_node[j]->Z()); - vector d = a - b; + Vector a(mb_node[i]->X(), mb_node[i]->Y(), mb_node[i]->Z()); + Vector b(mb_node[j]->X(), mb_node[j]->Y(), mb_node[j]->Z()); + Vector d = a - b; if (d.length() < RANGE) return true; @@ -803,8 +803,6 @@ num_nodes = atoi(argv[2]); assert(num_nodes > 0); - - printf("num_nodes is set %d\n", num_nodes); min_hops = new int[num_nodes * num_nodes]; mb_node = new MobileNode*[num_nodes]; diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/god.h ns/god.h --- ns-allinone-2.1b7a/ns-2.1b7a/god.h Mon Jul 10 09:24:45 2000 +++ ns/god.h Fri Mar 2 10:17:12 2001 @@ -76,39 +76,39 @@ // Cut and Paste from setdest.h -- Chalermek 12/1/99 -class vector { +class Vector { public: - vector(double x = 0.0, double y = 0.0, double z = 0.0) { + Vector(double x = 0.0, double y = 0.0, double z = 0.0) { X = x; Y = y; Z = z; } double length() { return sqrt(X*X + Y*Y + Z*Z); } - inline void vector::operator=(const vector a) { + inline void Vector::operator=(const Vector a) { X = a.X; Y = a.Y; Z = a.Z; } - inline void vector::operator+=(const vector a) { + inline void Vector::operator+=(const Vector a) { X += a.X; Y += a.Y; Z += a.Z; } - inline int vector::operator==(const vector a) { + inline int Vector::operator==(const Vector a) { return (X == a.X && Y == a.Y && Z == a.Z); } - inline int vector::operator!=(const vector a) { + inline int Vector::operator!=(const Vector a) { return (X != a.X || Y != a.Y || Z != a.Z); } - inline vector operator-(const vector a) { - return vector(X-a.X, Y-a.Y, Z-a.Z); + inline Vector operator-(const Vector a) { + return Vector(X-a.X, Y-a.Y, Z-a.Z); } - friend inline vector operator*(const double a, const vector b) { - return vector(a*b.X, a*b.Y, a*b.Z); + friend inline Vector operator*(const double a, const Vector b) { + return Vector(a*b.X, a*b.Y, a*b.Z); } - friend inline vector operator/(const vector a, const double b) { - return vector(a.X/b, a.Y/b, a.Z/b); + friend inline Vector operator/(const Vector a, const double b) { + return Vector(a.X/b, a.Y/b, a.Z/b); } double X; Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/cmu-scen-gen/setdest: Makefile Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/cmu-scen-gen/setdest: calcdest Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/cmu-scen-gen/setdest: calcdest.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/cmu-scen-gen/setdest: rng.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/cmu-scen-gen/setdest: setdest Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/cmu-scen-gen/setdest: setdest.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: Makefile Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: dec-tr-stat Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: formsquid.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: formtxt.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: my-endian.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: proxytrace.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: proxytrace2any.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/dec: tr-stat.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/epa: Makefile Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/epa: epa-tr-stat Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/epa: tr-stat.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/nlanr: Makefile Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/nlanr: logparse.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/nlanr: nlanr-tr-stat Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/nlanr: tr-stat.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/ucb: Makefile Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/ucb: logparse.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/ucb: tr-stat.o Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/ucb: ucb-tr-stat Only in ns-allinone-2.1b7a/ns-2.1b7a/indep-utils/webtrace-conv/ucb: utils.o diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/README ns/olsr/README --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/README Thu Jan 1 01:00:00 1970 +++ ns/olsr/README Wed May 9 12:19:46 2001 @@ -0,0 +1,100 @@ + + +OLSR Implementation for Network Simulator 2 + +This directory contains the source code for the implementation of the +Optimized Link State MANET Routing protocol for Network Simulator 2. + +See http://www.cs.auc.dk/~larsch/dat5/olsr-ns/ for the latest +snapshot. + + +CONFIGURATION + + The olsr protocol can be configured by creating a configuration file in +the current work directory of the ns simulation process. Each line of the file +has the following format: + + variable value + + By default, olsr tries to load the configuration from "olsr.cfg", but +you can configure this file name by setting the OLSRCFG environment variable to +the name of the file before you start the simulation. [not yet implemented - +just create olsr.cfg] + +Possible configuration variables (and their defaults) are: + + packet_jitter (default 0.5) + + Maximum random time to withhold any olsr packet before + transmitting (both self-generated and flooding). + + hello_interval (default 2.0) + + Time between generating a hello message. + + hello_jitter (default 1.0) + + Maximum random time to add to the hello_interval + (regenerated each interval) + + tc_interval (default 5.0) + + Time between generating a tc message. + + tc_jitter (default 1.0) + + Maximum random time to add to the tc_interval + (regenerated each interval) + + neighbour_hold_time (default 6.0) + + Timeout for neighbour entries + + topology_hold_time (default 16.0) + + Timeout for topology entries + + duplicate_hold_time (default 60.0) +LOG + + Besides from the NS trace, OLSR can write a OLSR log of olsr messages. +Set the OLSRLOG environment variable to the of the log file before you run the +simulation to get a log file. The log file has the following format: + + event time node-address msg-type source-addr [extra] + + event ::= "r" | "s" | "f" | "D" + + // for "recieve", "send", "forward" and "drop" events + +Extra information is provived for some events: + + send-tc-extra ::= tc_msg_seq mssn orignator + + send-hello-extra ::= hell_msg_seq mprset_seqnum + + recv-hello-extra ::= msg_seq + + drop-tc-extra ::= msg_seq mssn originator reason + + recv-tc-extra ::= msg_seq mssn originator + + forward-tc-extra ::= msg_seq mssn originator + +BUGS + + * No known bugs + +MINOR ISSUES + + * MPR selection is done each time a hello message is + received. This shouldn't affect the optimality of the protocol, + but is an computational overhead. The MPR set sequence number + isn't updated unless there is a change to the mpr set. + +TODO + + * Implement MPR optimization (post-reduction). + + diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/constants.hh ns/olsr/constants.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/constants.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/constants.hh Wed May 9 12:19:47 2001 @@ -0,0 +1,50 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +/* + +configurable now + +#define HELLO_INTERVAL 1 +#define HELLO_JITTER 1 + +#define TC_INTERVAL 4 +#define TC_JITTER 1 + +#define TC_MIN_INTERVAL 2 + +#define NEIGHB_HOLD_TIME 6 +#define TOP_HOLD_TIME 16 +#define DUP_HOLD_TIME 60 + +*/ + +#define TC_TTL 100 + +#define FLUSH_INTERVAL 0.010 +#define FLUSH_JITTER 0.005 diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/duptable.cc ns/olsr/duptable.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/duptable.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/duptable.cc Wed May 9 12:19:47 2001 @@ -0,0 +1,70 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// duptable.cc - duplicate table + +#include "config.h" +#include "duptable.hh" +#include "constants.hh" +#include "olsrcfg.hh" + +dupentry::dupentry() + : perishable(olsrcfg.duplicate_hold_time) { +} + +dupentry::dupentry(u_int16_t seq_num) + : perishable(olsrcfg.duplicate_hold_time), seq_num_(seq_num) { +} + +duptable::duptable() { + +} + +void dupentry::update(u_int16_t seq_num) { + seq_num_ = seq_num; + freshen(); +} + +// returns true if the + +bool duptable::update(u_int32_t addr, u_int16_t seq_num) { + iterator i = find(addr); + if (i == end()) { + // does not exist, then create + operator[](addr) = dupentry(seq_num); + return true; // was updated + } else { + // does exist. update if newer + if (seq_num > i->second.seq_num()) { + i->second.update(seq_num); + return true; + } else { + return false; + } + } +} diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/duptable.hh ns/olsr/duptable.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/duptable.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/duptable.hh Wed May 9 12:19:47 2001 @@ -0,0 +1,60 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __duptable_hh__ +#define __duptable_hh__ + +#include + +#include + +class dupentry : public perishable { + u_int16_t seq_num_; + +public: + dupentry(); + dupentry(u_int16_t seq_num); + + u_int16_t seq_num() { return seq_num_; } + void update(u_int16_t seq_num); +}; + +// Duplicate TC Message Table. Used to store sequence numbers from TC +// messages so that we do no process old messages nor more than once. + +class duptable : public map { +public: + duptable(); + + // Updates the duplicate table with tc seq_num originating from + // addr. Returns true if the duptable is updated (didn't get that + // packet already). + bool update(u_int32_t addr, u_int16_t seq_num); +}; + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/mpr2.cc ns/olsr/mpr2.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/mpr2.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/mpr2.cc Wed May 9 12:19:47 2001 @@ -0,0 +1,210 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// mpr2.cc - MRP selection algorithm + +#include "config.h" +#include "neighbor.hh" +#include "mpr2.hh" + +typedef u_int32_t addr_t; + +// Terms: +// +// A onehop node is a node to which we have a symmetric link. A twohop +// node is a node to which we have no symmetric link but for which +// there exists a onehop node that does have a symmetric link to that +// node [not ourself]. +// +// We keep a table with one hop neighbors and one with two hop +// neighbors. Each entry in the onehop table contains a set of +// pointers to the two hops nodes that the node can reach and that are +// not already covered. The two hop table contains a set of pointers +// to the onehop neighbors that can reach it. + +////////////////////////////////////////////////////////////////////// +// TYPES + +struct onehop; +struct twohop; + +struct onehop { + set twohops; // twohops that are not yet reachable. Updated when we cover new nodes. + nbentry *nb; + int degree; + + onehop() : nb(0) {} +}; + +struct twohop { + set onehops; // onehops that reach this twohop. Static. +}; + +typedef map onehop_table; +typedef map twohop_table; + +////////////////////////////////////////////////////////////////////// +// VARIABLES + +static onehop_table onehops; +static twohop_table twohops; +static set future_mprs; + +////////////////////////////////////////////////////////////////////// +// PROTOTYPES + +static void make_mpr(onehop *oh); +static void initialize_tables(nbtable &neighbors); +static void update_neighbors(nbtable &neighbors); +static void make_covered(twohop *th); + +////////////////////////////////////////////////////////////////////// +// FUNCTIONS + +// mpr_run runs the mpr algorithm and updates the neighbor table + +void mpr_run(nbtable &neighbors) { + initialize_tables(neighbors); + + // Add single path two hop nodes + + for (twohop_table::iterator i = twohops.begin(); i != twohops.end(); i++) { + twohop &th = i->second; + + if (th.onehops.size() == 1) + make_mpr(*th.onehops.begin()); + } + + // Add onehops that reach most uncovered twohops + while (true) { + int record = -1; // twohopcount record + onehop *record_holder = NULL; + + for (onehop_table::iterator i = onehops.begin(); + i != onehops.end(); i++) { + + onehop &oh = i->second; + int twohopcount = oh.twohops.size(); + if (twohopcount == record && oh.degree > record_holder->degree) { + record_holder = &oh; + } else if (twohopcount > record) { + record = twohopcount; + record_holder = &oh; + } + + } + + if (!(record >= 1)) + break; // if no onehops of interest found, break. + + make_mpr(record_holder); + }; + + update_neighbors(neighbors); +} + +static void initialize_tables(nbtable &neighbors) { + onehops.clear(); + twohops.clear(); + future_mprs.clear(); + + for (nbtable::iterator i = neighbors.begin(); i != neighbors.end(); i++) { + addr_t addr = i->first; + nbentry &nb = i->second; + + if (!nb.is_neighbor()) + continue; + + onehop &oh = onehops[addr]; + oh.nb = &nb; + nb.set_status(link_sym); + + // Iterator over twohop neighbors + for (addr_set_t::iterator j = nb.two_hop_list().begin(); j != nb.two_hop_list().end(); j++) { + addr_t twohop_addr = *j; + + // skip real neighbors + if (neighbors.is_real_neighbor(twohop_addr)) + continue; + + twohop &th = twohops[twohop_addr]; + // insert twohop pointer in onehop + oh.twohops.insert(&th); + // insert onehop pointer in twohop + th.onehops.insert(&oh); + } + + oh.degree = oh.twohops.size(); + } +} + +// When a twohop become covered, we remove that twohop from all the +// onehops that can reach it. + +static void make_covered(twohop *th) { + for (set::iterator i = th->onehops.begin(); i != th->onehops.end(); i++) { + (*i)->twohops.erase(th); + } +} + +// When a onehop becomes MPR, we cover all the twohops that the onehop +// can reach. + +static void make_mpr(onehop *oh) { + for (set::iterator i = oh->twohops.begin(); + i != oh->twohops.end(); i++) { + make_covered(*i); + } + future_mprs.insert(oh->nb); +} + +// Updates the neighbor table according to the selected mpr set. + +static void update_neighbors(nbtable &neighbors) { + bool mprset_changed = false; + + for (nbtable::iterator i = neighbors.begin(); i != neighbors.end(); i++) { + nbentry *nb = &i->second; + + if (!nb->is_neighbor()) + continue; + + link_type_t new_status; + if (future_mprs.find(nb) != future_mprs.end()) + new_status = link_mpr; + else + new_status = link_sym; + + if (nb->status() != new_status) { + nb->set_status(new_status); + mprset_changed = true; + } + } + if (mprset_changed) + neighbors.newmprsetseqnum(); +} diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/mpr2.hh ns/olsr/mpr2.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/mpr2.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/mpr2.hh Wed May 9 12:19:47 2001 @@ -0,0 +1,38 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __olsr_mpr2_hh__ +#define __olsr_mpr2_hh__ + +// Run the MPR selection algorithm and updates the neighbor +// table. Returns true if there were changes to the mpr set and false +// if not. + +void mpr_run(nbtable &neighbors); + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/mprselector.cc ns/olsr/mprselector.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/mprselector.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/mprselector.cc Wed May 9 12:19:47 2001 @@ -0,0 +1,32 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// mprselector.cc - mpr selector table + +#include "config.h" +#include diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/mprselector.hh ns/olsr/mprselector.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/mprselector.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/mprselector.hh Wed May 9 12:19:48 2001 @@ -0,0 +1,71 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __olsr_ms_hh__ +#define __olsr_ms_hh__ + +#include + +#include "types.hh" +#include "constants.hh" +#include "perishable.hh" +#include "olsrcfg.hh" + +// mpr selector entry. Stores only the sequence number of the mpr +// selected of the neighbor + +class ms_entry : public perishable { + u_int16_t mpr_seq_; + +public: + ms_entry() + : perishable(olsrcfg.neighbour_hold_time), mpr_seq_(0) {} + ms_entry(u_int16_t ms_seq) + : perishable(olsrcfg.neighbour_hold_time), mpr_seq_(ms_seq) {} + + u_int16_t mpr_seq() { return mpr_seq_; } + void mpr_seq(u_int16_t mpr_seq) { mpr_seq_ = mpr_seq; } +}; + + +// MPR Selector Table. Stores the addresses of the nodes which have +// selected us as their MPR. + +class olsr_ms : public map { +public: + u_int32_t ms_seq; // MPR Selector Set Sequence Number (MSSN) + + olsr_ms() : ms_seq(0) {} + virtual ~olsr_ms() {} + + bool contains(addr_t addr) { + return (find(addr) != end()); + } +}; + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/neighbor.cc ns/olsr/neighbor.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/neighbor.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/neighbor.cc Wed May 9 12:19:48 2001 @@ -0,0 +1,74 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// neighbor.cc - Neighbour table + +#include + +#include "neighbor.hh" +#include "packet.hh" +#include "constants.hh" +#include "olsrcfg.hh" + +perishable::perishable(double max_age) : max_age_(max_age) { + freshen(); +} + +bool perishable::too_old() { + return (timeout_ < Scheduler::instance().clock()); +} + +void perishable::freshen() { + timeout_ = Scheduler::instance().clock() + max_age_; +} + +nbentry::nbentry() + : perishable(olsrcfg.neighbour_hold_time), link_status_(link_asym) { +} + +nbentry::nbentry(u_int8_t link_status) + : perishable(olsrcfg.neighbour_hold_time), link_status_(link_status) { +} + +void nbentry::add2hopnode(u_int32_t addr) { + hop2list_.insert(addr); +} + +void nbentry::clear2hoplist() { + hop2list_.clear(); +} + +bool nbtable::is_real_neighbor(u_int32_t addr) { + iterator f = find(addr); + return ( (f != end()) && (f->second.status() != link_asym) ); +} + +bool nbtable::is_asym_neighbor(u_int32_t addr) { + iterator f = find(addr); + return ( (f != end()) && (f->second.status() == link_asym) ); +} diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/neighbor.hh ns/olsr/neighbor.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/neighbor.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/neighbor.hh Tue Jun 26 14:44:56 2001 @@ -0,0 +1,121 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __olsr_neighbor_hh__ +#define __olsr_neighbor_hh__ + +#include +#include +#include +#include +#include + +#include "packet.hh" +#include "perishable.hh" + +typedef set addr_set_t; + +class nbentry : public perishable { +protected: + u_int8_t link_status_; + addr_set_t hop2list_; + double *hello_times; + +public: + nbentry(u_int8_t link_status = link_asym); + ~nbentry(); + + void add2hopnode(u_int32_t addr); + void clear2hoplist(); + + u_int8_t link_type() { + return link_status_; + } + + void set_status(int status) { + link_status_ = status; + } + + u_int8_t status() const { + return link_status_; + } + + const addr_set_t &two_hop_list() const { + return hop2list_; + } + + bool is_neighbor() { + return link_status_ == link_mpr || link_status_ == link_sym; + } + + // nbentry::hello_received() records that a hello message has been + // received from this neighbor at this time and upgrades from + // link_seen to link_asym if enought packets according to the + // configuration has been received. + + void hello_received(); + + // make this my friend + + friend class mpr_algo; +}; + +class nbtable : public map { +public: + void cleanup() { + iterator i, next; + next = begin(); + while (i=next, i!=end()) { + next++; + if ((*i).second.too_old()) + erase(i); + } + } + + // Checks if an address is a real neighbor. That is + // a neighbor with a bidirectional link to us. + + bool is_real_neighbor(u_int32_t addr); + + // Checks if an address belongs to an aymmetric neighbor + + bool is_asym_neighbor(u_int32_t addr); + + void newmprsetseqnum() { + mprset_seqnum_++; + } + u_int16_t mprset_seqnum() { return mprset_seqnum_; } + + nbtable() : mprset_seqnum_(0) {} + +protected: + uint mprset_seqnum_; +}; + + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/ns-olsragent.cc ns/olsr/ns-olsragent.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/ns-olsragent.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/ns-olsragent.cc Wed May 16 17:12:40 2001 @@ -0,0 +1,280 @@ +// Copyright (c) 2000, 2001 Lars Christensen + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// ns-olsragent.cc - Network Simulator Interface for OLSR + +#include "ns-olsragent.hh" +#include "packet.hh" + +#include + +#define TIME (Scheduler::instance().clock()) + +/// Utility functions //////////////////////////////////////////////// + +/* check if the arg[cv] matches a specific command and a given number + of additional arguments. returns 1 if it is with + . */ + +int command_is(const char *command, int nargs, int argc, const char *const *argv) { + return (argc==2+nargs) && (strcmp(command, argv[1]) == 0); +} + +/// TCL Interface classes //////////////////////////////////////////// + +static class OLSRclass : public TclClass { +public: + OLSRclass() : TclClass("Agent/OLSR") {} + TclObject *create(int argc, const char *const *argv) { + assert(argc==5); + return (new NS_OLSRAgent((nsaddr_t)atoi(argv[4]))); + } +} class_rtProtoOLSR; + +static class OLSRHeaderClass : public PacketHeaderClass { +public: + OLSRHeaderClass() : PacketHeaderClass("PacketHeader/OLSR", + OLSR_HDR_LEN) { } +} class_rtProtoOLSR_hdr; + +/// Timer Implementations //////////////////////////////////////////// + +void hello_timer::handle(Event *) { + double interval; + + if (first_time) { + // Wait a little to avoid collisions + interval = 2.0 * Random::uniform(); + first_time = false; + } else { + agent->sendHello(); + interval = olsrcfg.hello_interval + olsrcfg.hello_jitter * Random::uniform(); + } + Scheduler::instance().schedule(this, &intr, interval); +} + +void tc_timer::handle(Event *) { + double interval; + agent->sendTC(); + interval = olsrcfg.tc_interval + olsrcfg.tc_jitter * Random::uniform(); + Scheduler::instance().schedule(this, &intr, interval); +} + +void flush_timer::handle(Event *) { + agent->flush(); +} + +void flush_timer::schedule(double time) { + Scheduler::instance().schedule(this, &intr, time); +} + +/// OLSR Agent Implementation //////////////////////////////////////// + +NS_OLSRAgent::NS_OLSRAgent(nsaddr_t id) + : Agent(PT_OLSR), olsr(*this, (u_int32_t)id), myaddr_(id), + hellotimer_(this), tctimer_(this), flushtimer_(this), + flush_scheduled(false) +{ +} + +NS_OLSRAgent::~NS_OLSRAgent() { +} + +int NS_OLSRAgent::command(int argc, const char *const *argv) { + + if (command_is("id", 0, argc, argv)) { + + /* return the id of this node */ + Tcl &tcl = Tcl::instance(); + tcl.resultf("%d", myaddr_); + return TCL_OK; + + } else if (command_is("start", 0, argc, argv)) { + + // start simulation + hellotimer_.handle((Event*)0); + tctimer_.handle((Event*)0); + flushtimer_.handle((Event*)0); + return TCL_OK; + + } else if (command_is("index", 1, argc, argv)) { + + /* set the id of this router agent */ + myaddr_ = atoi(argv[2]); + return TCL_OK; + + } else if (command_is("log-target", 1, argc, argv) + || command_is("tracetarget", 1, argc, argv)) { + + /* set the trace object */ + logtarget = (Trace*)TclObject::lookup(argv[2]); + if (!logtarget) + return TCL_ERROR; + else + return TCL_OK; + + } + + /* let the superclass handle */ + return Agent::command(argc, argv); + + +} + +void NS_OLSRAgent::recv(Packet *p, Handler *) { + /* common header */ + struct hdr_cmn *ch = HDR_CMN(p); + /* ip header */ + struct hdr_ip *ih = HDR_IP(p); + + //cout << "NS_OLSRAgent::recv(type=" << ch->ptype() << ", src=" << ih->saddr() << ", dst=" << ih->daddr() << "); [" << myaddr_ << "]" << endl; + + if (ch->ptype() == PT_OLSR) { + ih->ttl_ -= 1; + + u_int8_t *data = (u_int8_t*)p->accessdata(); + int packet_size = p->datalen(); + olsr_packet pck(data, packet_size); + + olsr.recv(ih->saddr(), pck); + + Packet::free(p); + return; + } + + if (ih->saddr() == myaddr_) { + + if (ch->num_forwards() == 0) { + ch->size() += IP_HDR_LEN; + ih->ttl_ = NETWORK_DIAMETER; + } else { + drop(p, DROP_RTR_ROUTE_LOOP); + } + + } else if (--ih->ttl_ == 0) { + drop(p, DROP_RTR_TTL); + return; + } + + /* route the packet */ + + const routetable &rtable = olsr.routingtable(); + routetable::const_iterator f = rtable.find(ih->daddr()); + if (f != rtable.end()) { + forward(p, f->second.next_hop); + } else { + drop(p, DROP_RTR_NO_ROUTE); + } +} + +void NS_OLSRAgent::forward(Packet *p, addr_t nexthop) { + struct hdr_cmn *ch = HDR_CMN(p); + struct hdr_ip *ih = HDR_IP(p); + + /* check ttl */ + if (ih->ttl_ == 0){ + drop(p, DROP_RTR_TTL); + return; + } + + ch->prev_hop_ = myaddr_; + ch->next_hop_ = nexthop; + ch->addr_type() = NS_AF_INET; + ch->direction() = hdr_cmn::DOWN; + + // Send the packet + Scheduler::instance().schedule(target_, p, 0.); + //target_->recv(p, (Handler*)0); +} + +void NS_OLSRAgent::sendPacket(olsr_packet &pck) { + Packet *p = allocpkt(pck.size()); + + // Fill common header + struct hdr_cmn *ch = HDR_CMN(p); + ch->ptype() = PT_OLSR; + ch->size() = IP_HDR_LEN; + ch->iface() = -2; + ch->error() = 0; + ch->addr_type() = NS_AF_NONE; + ch->prev_hop_ = myaddr_; + + // Fill IP header + struct hdr_ip *ih = HDR_IP(p); + ih->saddr() = myaddr_; + ih->daddr() = IP_BROADCAST; + ih->sport() = RT_PORT; + ih->dport() = RT_PORT; + ih->ttl_ = 1; + + memcpy(p->accessdata(), pck.data(), pck.size()); + + if (olsrcfg.packet_jitter > 0) { + Scheduler::instance().schedule(target_, p, + olsrcfg.packet_jitter * Random::uniform()); + } else { + target_->recv(p, (Handler*)0); + } +} + +void NS_OLSRAgent::sendHello() { + olsr.sendHello(); + flushpacketbuffer(); +} + +void NS_OLSRAgent::sendTC() { + olsr.sendTC(); + flushpacketbuffer(); +} + +void NS_OLSRAgent::flush() { + olsr.flush(); + flushpacketbuffer(); + flush_scheduled = false; +} + +void NS_OLSRAgent::flushpacketbuffer() { + OLSR::packetqueue_t &pq = olsr.get_packetqueue(); + olsr_packet *pck; + while (!pq.empty()) { + pck = pq.front(); + pq.pop(); + //printf("Sending %p\n", pck); + sendPacket(*pck); + } +} + +void NS_OLSRAgent::schedule_flush(double time) { + if (!flush_scheduled) { + flushtimer_.schedule(time); + flush_scheduled = true; + } +} + +double sys_time() { + return Scheduler::instance().clock(); +} diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/ns-olsragent.hh ns/olsr/ns-olsragent.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/ns-olsragent.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/ns-olsragent.hh Wed May 9 12:19:48 2001 @@ -0,0 +1,121 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __olsragent_hh__ +#define __olsragent_hh__ + +#include "olsr.hh" + +#include +#include +#include +#include +#include +#include +#include + +// predeclarations + +class NS_OLSRAgent; + +////////////////////////////////////////////////////////////////////// +// Timers + +// Hello Timer /////////////////////////////////////////////////////// + +class hello_timer : public Handler { +public: + hello_timer(NS_OLSRAgent *o) : agent(o), first_time(true) {} + void handle(Event*); +private: + NS_OLSRAgent *agent; + Event intr; + bool first_time; +}; + +// TC Timer ////////////////////////////////////////////////////////// + +class tc_timer : public Handler { +public: + tc_timer(NS_OLSRAgent *o) : agent(o) {} + void handle(Event*); +private: + NS_OLSRAgent *agent; + Event intr; +}; + +// Queue Flush Timer ///////////////////////////////////////////////// + +class flush_timer : public Handler { +public: + flush_timer(NS_OLSRAgent *o) : agent(o) {} + void handle(Event*); + void schedule(double time); +private: + NS_OLSRAgent *agent; + Event intr; +}; + +class NS_OLSRAgent : public Agent, public OLSRAgent { + OLSR olsr; +public: + NS_OLSRAgent(nsaddr_t id); + ~NS_OLSRAgent(); + + void recv(Packet *p, Handler *); + void forward(Packet *p, addr_t nexthop); + + void flushpacketbuffer(); + void sendHello(); + void sendTC(); + void flush(); + + virtual void schedule_flush(double time); + +protected: + + void sendPacket(olsr_packet &pck); + + Trace *logtarget; // routing table logging + + // TCL Interface + int command(int, const char *const *); + + int myaddr_; // node id + int off_OLSR_; // header offset + + hello_timer hellotimer_; + tc_timer tctimer_; + flush_timer flushtimer_; + + bool flush_scheduled; +}; + +double sys_time(); // returns the system time. + +#endif __olsragent_hh__ diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsr.cc ns/olsr/olsr.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsr.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/olsr.cc Wed May 30 12:56:53 2001 @@ -0,0 +1,641 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// olsr.cc - OLSR core + +#define debugnode 99999 + +#include +#include +#include + +#include "olsr.hh" +#include "packet.hh" +#include "constants.hh" +#include "mpr2.hh" +#include "olsrcfg.hh" + +olsr_configuration olsrcfg; + +olsr_configuration::olsr_configuration() { + + // set defaults + packet_jitter = 0.5; + hello_interval = 2.0; + hello_jitter = 1.0; + tc_interval = 5.0; + tc_jitter = 1.0; + holdback_time = 0.0; + neighbour_hold_time = 6.0; + topology_hold_time = 16.0; + duplicate_hold_time = 60.0; + route_reverse_links = false; + + ifstream f("olsr.cfg"); + if (f.is_open()) { + while (!f.eof()) { + string var; + double val; + f >> var >> val; + + if (var == "") + continue; + + if (var == "packet_jitter") + packet_jitter = val; + else if (var == "hello_interval") + hello_interval = val; + else if (var == "hello_jitter") + hello_jitter = val; + else if (var == "tc_interval") + tc_interval = val; + else if (var == "tc_jitter") + tc_jitter = val; + else if (var == "holdback_time") + holdback_time = val; + else if (var == "neighbour_hold_time") + neighbour_hold_time = val; + else if (var == "topology_hold_time") + topology_hold_time = val; + else if (var == "duplicate_hold_time") + duplicate_hold_time = val; + else if (var == "route_reverse_links") + route_reverse_links = true; + else + cerr << "invalid olsr configuration parameter (olsr.conf): " << var << " " << val << endl; + } + } + cerr << "OLSRCFG:" + << " packet_jitter=" << packet_jitter + << " hello_interval=" << hello_interval + << " hello_jitter=" << hello_jitter + << " tc_interval=" << tc_interval + << " tc_jitter=" << tc_jitter + << " holdback_time=" << holdback_time + << " neighbour_hold_time=" << neighbour_hold_time + << " topology_hold_time=" << topology_hold_time + << " duplicate_hold_time=" << duplicate_hold_time + << " route_reverse_links=" << route_reverse_links + << endl; +}; + +// USE_LOG: define as 1 if you want the OLSR instances to write to a +// common log file. All OLSR event on the message level is written. + +#define USE_LOG 1 + +#if USE_LOG +#define OLSRLOG(foo) olsr_log << foo +#else +#define OLSRLOG(foo) +#endif + +int OLSR::olsr_log_count = 0; +ofstream OLSR::olsr_log; + +OLSR::OLSR(OLSRAgent &oa, addr_t myaddr) + : agent(oa), myaddr_(myaddr), hello_msg_seq(0), tc_msg_seq(0), mssn(1), + neighborhood_changed(false), mprselectorset_changed(false) +{ +#if USE_LOG + if (olsr_log_count == 0) { + char *logfilename; + logfilename = getenv("OLSRLOG"); + if (logfilename == NULL) + logfilename = "olsr.log"; + olsr_log.open(logfilename); + } + olsr_log_count++; +#endif +} + +OLSR::~OLSR() { +#if USE_LOG + olsr_log_count--; + if (olsr_log_count == 0) + olsr_log.close(); +#endif +} + +void OLSR::recv(addr_t saddr, olsr_packet &pck) { + // clean up to make sure we don't have outdated information + cleanup(); + + // cout << myaddr_ << " got an olsr packet from " << saddr << ", size " << packet_size << endl; + //cout << *pck.hdr() << endl; + + for (olsr_message_hdr *hdr = pck.first_message(); hdr != 0; + hdr = pck.next_message(hdr)) { + + switch (hdr->msg_type) { + case msgtype_hello: + recvHello(saddr, pck.message_data(hdr), pck.message_size(hdr)); + break; + case msgtype_tc: + recvTC(saddr, pck.message_data(hdr), pck.message_size(hdr)); + break; + default: + // Check if we should forward this message + /* This is dangerous! + if (hdr->is_broadcast()) { + if (mpr_selectors.contains(saddr)) + forwardMessage((u_int8_t*)hdr, hdr->length); + } + */ + break; + } + + } + + postProcess(); +} + +// sendTC composes and transmit TC messages + +void OLSR::sendTC() { + + if (mpr_selectors.size() == 0) + return; + + // clean up to make sure we don't have outdated information + cleanup(); + postProcess(); + + if (mprselectorset_changed) { + mssn++; + mprselectorset_changed = false; + } + //cout << myaddr_ << " sends TC " << tc_msg_seq << endl; + olsr_tc_msg tc_msg(tc_msg_seq++, mssn, TC_TTL, myaddr_ /* originator */); + olsr_ms::iterator i; + for (i = mpr_selectors.begin(); i!=mpr_selectors.end(); i++) { + u_int32_t addr = i->first; + tc_msg.add_mprs_address(addr); + } + + OLSRLOG("s " << sys_time() << " " << myaddr_ << " tc - " << tc_msg_seq-1 << " " << mssn << " " << myaddr_ << endl); + + olsr_packet *pck = new olsr_packet; + pck->append_tc_msg(tc_msg); // add tc msg + sendPacket(pck); +} + +void OLSR::sendHello() { + // clean up to make sure we don't have outdated information + cleanup(); + postProcess(); + + olsr_hello_msg hello_msg(hello_msg_seq++, neighbors.mprset_seqnum()); + // for each known link type + for (int link_type = 1; link_type < link_max; link_type++) { + bool did_start_link_type = false; + + for (nbtable::iterator i = neighbors.begin(); i != neighbors.end(); i++) { + // add the entries in the nbtable that are of this type + nbentry &nb = i->second; + u_int32_t addr = i->first; + if (nb.link_type() == link_type) { + if (!did_start_link_type) { + hello_msg.start_link_type(link_type); + did_start_link_type = true; + } + hello_msg.add_address(addr); + } + } + } + + OLSRLOG("s " << sys_time() << " " << myaddr_ << " hello - " << hello_msg_seq-1 << " " << neighbors.mprset_seqnum() << endl); + + olsr_packet *pck = new olsr_packet; + pck->append_hello_msg(hello_msg); + sendPacket(pck); +} + +void OLSR::recvHello(u_int32_t saddr, u_int8_t *data, int length) { + olsr_hello_msg_parser mp(data, length); + + OLSRLOG("r " << sys_time() << " " << myaddr_ << " hello " << saddr << " " << mp.msg_seq() <<" " << mp.mpr_seq() << endl); + + nbtable::iterator nbi = neighbors.find(saddr); // lookup the neighbor + + nbentry *nb; + + if (nbi == neighbors.end()) { // no exiting entry + // create entry + nb = &neighbors[saddr]; + nb->set_status(link_asym); // will perhaps be upgraded later + } else { + nb = &(*nbi).second; + nb->freshen(); + nb->clear2hoplist(); + } + + bool found_myself = false; // we need to know + link_type_t self_status = link_undef; + + while (mp.more_link_types()) { + link_type_t link_type = mp.next_link_type(); + + while (mp.more_addresses()) { + u_int32_t addr = mp.next_address(); + + if (addr == (u_int32_t)myaddr_) { + + found_myself = true; + self_status = link_type; + + } else { + + + // add the node as 2hop if it is not in nbtable + // and link_type is sym or mpr + + if (link_type == link_sym || link_type == link_mpr) { + if (!neighbors.is_real_neighbor(addr)) + nb->add2hopnode(addr); + } + } + } + } + + if (found_myself) { + // If we found ourselves, we should upgrade asym to sym. If not, + // we must always downgrade. + + if (nb->status() == link_asym) + if (self_status == link_asym || self_status == link_sym || self_status == link_mpr) + nb->set_status(link_sym); + + if (self_status == link_mpr) { + // Update MPR Selector Table + + // if doesn't already exist, we have a change + if (mpr_selectors.find(saddr) == mpr_selectors.end()) + mprselectorset_changed = true; + + ms_entry &ms = mpr_selectors[saddr]; + if (mp.mpr_seq() >= ms.mpr_seq()) { + ms.mpr_seq(mp.mpr_seq()); + ms.freshen(); + } + + if (mprselectorset_changed && myaddr_ == debugnode) + showMST(); + + } + + } else /* !found_myself */ { + // downgrade link if we didn't find ourselves + if (nb->status() == link_sym || nb->status() == link_mpr) { + nb->set_status(link_asym); + } + } + + neighborhood_changed = true; + + // Could be more precise but it would only affect computational + // overhead. + +} + +void OLSR::recvTC(u_int32_t saddr, const u_int8_t *data, int length) { + olsr_tc_msg_parser tc(data, length); + + bool drop = false; + string reason; + + // Ignore our own TCs + if (tc.originator() == (u_int32_t)myaddr_) { + drop = true; + reason = "my-own"; + } + + // Ignore TCs send from asymmetric neighbors + else if (neighbors.is_asym_neighbor(saddr)) { + drop = true; + reason = "from-asym-nb"; + } + + // Ignore older or already received tc's + else if (!duplicate_tcs.update(tc.originator(), tc.msg_seq())) { + drop = true; + reason = "duplicate"; + } + + if (drop) { + OLSRLOG("D " << sys_time() << " " << myaddr_ << " tc " << saddr << " " << tc.msg_seq() << " " << tc.mssn() << " " << tc.originator() << " " << reason << endl); + return; + } else { + OLSRLOG("r " << sys_time() << " " << myaddr_ << " tc " << saddr << " " << tc.msg_seq() << " " << tc.mssn() << " " << tc.originator() << endl); + } + + + // Forward message if necessary + if (mpr_selectors.contains(saddr)) { + if (tc.hopcount() > 0) { + OLSRLOG("f " << sys_time() << " " << myaddr_ << " tc " << saddr << " " << tc.msg_seq() << " " << tc.mssn() << " " << tc.originator() << endl); + forwardTCMessage(new olsr_tc_msg(data,length)); + } else { + cout << "HOPCOUNT IS ZERO - THAT IS NOT LIKELY!!!" << endl; + } + } + + // Update the topology + topology::iterator f = top.find(tc.originator()); + if (f != top.end()) { + if (f->second.seq_num() > tc.mssn()) { + // Silenty discard message if we have alread received newer + // information at some point. + return; + } + + if (f->second.seq_num() < tc.mssn()) { + // Discard outdated information + top.erase(f); + f = top.end(); + } + } + + if (f == top.end()) { + // Create new Entry + f = top.insert(top.begin(), + topology::value_type(tc.originator(), top_entry(tc.mssn()))); + } + + while (tc.more_addresses()) { + u_int32_t addr = tc.next_address(); + + top_entry::iterator e = f->second.find(addr); + + if (e == f->second.end()) { + // Create a new entry + f->second[addr] = top_selectorentry(); + } else { + // Freshen existing entry + e->second.freshen(); + } + } + tc.checkendcondition(); // check that we got all addresses + + topology_changed = true; + if (myaddr_ == debugnode) + showTopology(); +} + +void OLSR::calculateRoutingTable() { + rtable.clear(); + + // Insert all neighbors into the routing table with dist 1 + for (nbtable::iterator i = neighbors.begin(); i != neighbors.end(); i++) { + if (i->second.is_neighbor()) + rtable[i->first] = routeentry(i->first, 1); + } + + int h = 1; + bool inserted_any; + + do { + + inserted_any = false; + + for (topology::iterator i = top.begin(); i != top.end(); i++) { + u_int32_t last_hop = i->first; + top_entry &tent = i->second; + + // check that there is an entry in the routing table + routetable::iterator f = rtable.find(last_hop); + if (f != rtable.end() && f->second.dist == h) { + //routeentry &ent = f->second; + + for (top_entry::iterator j = tent.begin(); j != tent.end(); j++) { + if (j->first == (u_int32_t)myaddr_) + continue; + // insert all mpr selectors that does not already + // have a route with the routing entry's nexthop + // as nexthop. + if (rtable.find(j->first) == rtable.end()) { + rtable[j->first] = routeentry(f->second.next_hop, h+1); + inserted_any = true; + } + } + + } else if (f == rtable.end() && olsrcfg.route_reverse_links) { + // last_hop is not in route table + + // find the MPRSs that we have a route to with length + // h and add route to last_hop with h+1 + + for (top_entry::iterator j = tent.begin(); j != tent.end(); j++) { + if (j->first == (u_int32_t)myaddr_) + continue; + routetable::iterator f = rtable.find(j->first); + if (f != rtable.end() && f->second.dist == h) { + rtable[last_hop] = routeentry(f->second.next_hop, h+1); + inserted_any = true; + } + } + } + } + + h++; + } while (inserted_any); + + if (myaddr_ == debugnode) { + // cout << sys_time() << " - i have " << rtable.size() << " routes" << endl; + showRT(); + } +} + +void OLSR::showMST() { + cout << "MST for node " << myaddr_ << endl; + for (olsr_ms::iterator i = mpr_selectors.begin(); + i != mpr_selectors.end(); + i++) { + cout << " " << i->first << ": mpr_seq=" << i->second.mpr_seq() << endl; + } + cout << "ENDMST" << endl; +} + +void OLSR::showNBT() { + cout << "NB TABLE for node " << myaddr_ << endl; + for (nbtable::iterator i = neighbors.begin(); i != neighbors.end(); i++) { + cout << "\t" << (*i).first << ": status=" << link_type_name[int((*i).second.status())] << endl; + const addr_set_t &l = (*i).second.two_hop_list(); + cout << "\t\t2hop: "; + for (addr_set_t::const_iterator j = l.begin(); j != l.end(); j++) { + cout << " " << *j; + } + cout << endl; + } + cout << "ENDNEIGHBORS" << endl; +} + +void OLSR::showTopology() { + cout << "TOPOLOGY for node " << myaddr_ << endl; + for (topology::iterator i = top.begin(); i != top.end(); i++) { + cout << " MPR " << i->first << ", seq_num=" << i->second.seq_num() << endl; + cout << " SELECTORS"; + for (top_entry::iterator j = i->second.begin(); j != i->second.end(); j++) { + cout << " " << j->first; + } + cout << endl; + } +} + +void OLSR::showRT() { + cout << "Routing Table for node " << myaddr_ << endl; + for (routetable::iterator i = rtable.begin(); i != rtable.end(); i++) { + addr_t daddr = i->first; + routeentry &r = i->second; + cout << '\t' << daddr << '\t' << r.next_hop << '\t' << r.dist << endl; + } +} + +void OLSR::cleanup() { + + // clean up neighbor table + + { + nbtable::iterator i, next; + next = neighbors.begin(); + for (i = next; i != neighbors.end(); i = next) { + if (next != neighbors.end()) next++; + if (i->second.too_old()) { + neighbors.erase(i); + neighborhood_changed = true; + } + } + } + + // clean up the mss table + + { + olsr_ms::iterator i, next; + next = mpr_selectors.begin(); + for (i = next; i != mpr_selectors.end(); i = next) { + if (next != mpr_selectors.end()) next++; + if (i->second.too_old()) { + mpr_selectors.erase(i); + mprselectorset_changed = true; + } + } + } + + // clean up the duplicate table + + { + duptable::iterator i, next; + next = duplicate_tcs.begin(); + for (i = next; i != duplicate_tcs.end(); i = next) { + if (next != duplicate_tcs.end()) next++; + if (i->second.too_old()) { + duplicate_tcs.erase(i); + if (myaddr_ == debugnode) + showMST(); + } + } + } + + // clean up the topology table + + { + topology::iterator i, next; + next = top.begin(); + for (i = next; i != top.end(); i = next) { + if (next != top.end()) next++; + + top_entry &ts = i->second; + top_entry::iterator i2, next2; + next2 = ts.begin(); + for (i2 = next2; i2 != ts.end(); i2 = next2) { + if (next2 != ts.end()) next2++; + if (i2->second.too_old()) { + ts.erase(i2); + topology_changed = true; + } + } + + if (ts.size() == debugnode) + top.erase(i); + } + } +} + +void OLSR::forwardMessage(const u_int8_t *data, int length) { + olsr_packet *pck = new olsr_packet; + pck->append(data, length); + sendPacket(pck); +} + +void OLSR::forwardTCMessage(olsr_tc_msg *msg) { + msg->hdr()->hopcount--; + if (olsrcfg.holdback_time > 0.0) { + waiting_tcs.push_back(msg); + agent.schedule_flush(olsrcfg.holdback_time); + } else { + olsr_packet *pck = new olsr_packet; + pck->append_tc_msg(*msg); + delete msg; + sendPacket(pck); + } +} + +void OLSR::sendPacket(olsr_packet *pck) { + // piggyback any waiting tcs + for (list::iterator i = waiting_tcs.begin(); + i != waiting_tcs.end(); i++) { + pck->append_tc_msg(**i); + delete *i; + } + waiting_tcs.clear(); + packetqueue.push(pck); // queue for transmission +} + +void OLSR::updateMPRset() { + mpr_run(neighbors); + if (myaddr_ == debugnode) + showNBT(); +} + +void OLSR::postProcess() { + if (neighborhood_changed) + updateMPRset(); + + if (neighborhood_changed || topology_changed) + calculateRoutingTable(); + + neighborhood_changed = false; + topology_changed = false; +} + +void OLSR::flush() { + if (waiting_tcs.size() > 0) { + olsr_packet *pck = new olsr_packet; + sendPacket(pck); // Will add tcs + } +} diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsr.hh ns/olsr/olsr.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsr.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/olsr.hh Wed May 9 12:19:49 2001 @@ -0,0 +1,169 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __olsr_hh__ +#define __olsr_hh__ + +#include +#include + +#include "olsragent.hh" +#include "types.hh" + +#include "neighbor.hh" +#include "mprselector.hh" +#include "duptable.hh" +#include "topology.hh" + +// predeclerations + +extern double sys_time(); + +class OLSR; +class olsr_part; +class olsr_packet; + + +#define NETWORK_DIAMETER 32 +#define NO_DELAY (-1.0) + +#define OLSR_HDR_LEN 0 // (sizeof(hdr_olsr)) + +// Routing entry. Stores the next hop for at route to the destination +// node and the distance. + +struct routeentry { + u_int32_t next_hop; + int dist; + + routeentry() {} + routeentry(u_int32_t the_next_hop, + int the_dist) : next_hop(the_next_hop), dist(the_dist) { + } +}; + +// The routing table. Associates a destination entry with a route entry. + +typedef map routetable; + +// The OLSR Routing Agent + +class olsr_packet; + +class OLSR { +public: + + OLSR(OLSRAgent &oa, addr_t addr); + ~OLSR(); + + void sendHello(); + + void sendTC(); + void transmitTC(olsr_part &tc); + void flush(); + + void cleanup(); // clean up some tables + void sendPacket(olsr_packet *pck); + + // handle OLSR packet + void recv(addr_t saddr, olsr_packet &pck); + +protected: + int initialized() { return 1; } + + // handle HELLO message + void recvHello(u_int32_t saddr, u_int8_t *data, int length); + + // handle TC message + void recvTC(u_int32_t saddr, const u_int8_t *data, int length); + + // update MPR selector table + void updateMPRSelectorTable(u_int32_t saddr, u_int16_t mpr_seq); + // calculate the routing table + void calculateRoutingTable(); + // Do MPR selection + void updateMPRset(); + +public: + const routetable &routingtable() { return rtable; } + +protected: + OLSRAgent &agent; + addr_t myaddr_; + + nbtable neighbors; // neighbor table + routetable rtable; // routing table + olsr_ms mpr_selectors; // MPR selector table + duptable duplicate_tcs; // Duplicate table + topology top; // Topology table + + // Forward an OLSR message + void forwardMessage(const u_int8_t *data, int length); + void forwardTCMessage(olsr_tc_msg *part); + + // sequence numbers + u_int16_t hello_msg_seq; + u_int16_t tc_msg_seq; + u_int16_t mssn; + + // conditions + bool neighborhood_changed; + bool mprselectorset_changed; + bool topology_changed; + + list waiting_tcs; + +public: + typedef queue packetqueue_t; + packetqueue_t &get_packetqueue() { return packetqueue; } +protected: + packetqueue_t packetqueue; + + // post process depending on conditions + void postProcess(); + + // debugging functions + + // shows the mpr selector table + void showMST(); + // shows the nbtable + void showNBT(); + // shows the topology + void showTopology(); + // shows the routing table + void showRT(); + + static addr_t tc_show_addr; + static u_int16_t tc_show_seq; + static bool has_tc_show; + + static ofstream olsr_log; + static int olsr_log_count; // How many that are using the log stream +}; + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsragent.hh ns/olsr/olsragent.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsragent.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/olsragent.hh Thu May 3 13:10:44 2001 @@ -0,0 +1,12 @@ +#ifndef __olsr_agent_hh__ +#define __olsr_agent_hh__ + +class OLSRAgent { +public: + // schedule a flush in `time' seconds or before. Must be + // incremental, i.e. you cannot schedule a flush before an already + // scheduled flush. + virtual void schedule_flush(double time) = 0; +}; + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsrcfg.hh ns/olsr/olsrcfg.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/olsrcfg.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/olsrcfg.hh Mon May 28 15:21:06 2001 @@ -0,0 +1,40 @@ +#ifndef __olsrcfg_hh__ +#define __olsrcfg_hh__ + +struct olsr_configuration { + olsr_configuration(); + + // maximum jitter between packet generation and transmission + double packet_jitter; + + // maximum interval between hello packet generation + double hello_interval; + + // maximum shortening of the hello interval + double hello_jitter; + + // maximum interval between tc packet generation + double tc_interval; + + // maximum shortening of the tc interval + double tc_jitter; + + // maximum time to hold back messages for change to piggybag + double holdback_time; + + // timeout for neighbours + double neighbour_hold_time; + + // timeout for topology + double topology_hold_time; + + // timeout for duplicates + double duplicate_hold_time; + + // use reverse link in route calcs + bool route_reverse_links; +}; + +extern olsr_configuration olsrcfg; + +#endif __olsrcfg_hh__ diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/packet.cc ns/olsr/packet.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/packet.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/packet.cc Wed May 9 12:19:51 2001 @@ -0,0 +1,293 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// packet.cc - OLSR packet and message, encoding and decoding + +#include +#include + +#include "config.h" +#include "packet.hh" + +const char *link_type_name[link_max] = { + "null", + "asym", + "sym", + "mpr", +}; + +invalid_packet_format::invalid_packet_format() { + cerr << "[olsr] invalid_packet_format detected" << endl; + abort(); +} +invalid_packet_format::invalid_packet_format(const char *st) { + cerr << "[olsr] invalid packet format: " << st << endl; + abort(); +} + + +void olsr_part::dumpbin() { + int nwords = size() / sizeof(u_int32_t); + u_int32_t *p = (u_int32_t*)data(); + while (nwords--) { + cout.width(8); + cout.fill('0'); + ostream::fmtflags oldflags = cout.setf(ostream::hex |ostream::right, ostream::basefield); + cout << *p << endl; + p++; + cout.flags(oldflags); + } +} + +void olsr_packet::append_hello_msg(const olsr_part &p) { + olsr_message_hdr mh; + mh.msg_type = msgtype_hello; + mh.broadcast = 0; + mh.length = sizeof(olsr_message_hdr) + p.size(); + append((u_int8_t*)&mh, sizeof(mh)); + append(p); +} + +void olsr_packet::append_tc_msg(const olsr_part &p) { + olsr_message_hdr mh; + mh.msg_type = msgtype_tc; + mh.broadcast = BROADCAST; // TC messages are broadcast + mh.length = sizeof(olsr_message_hdr) + p.size(); + append((u_int8_t*)&mh, sizeof(mh)); + + append(p); +} + +olsr_message_hdr *olsr_packet::first_message() { + u_int8_t *firstmsg = data() + sizeof(olsr_hdr); + assert(firstmsg < data() + hdr()->length); + return (olsr_message_hdr*)(firstmsg); +} + +olsr_message_hdr *olsr_packet::next_message(olsr_message_hdr *msg_hdr) { + if (!(msg_hdr->length > 0)) throw invalid_packet_format(); + u_int8_t *nextmsg = ((u_int8_t*)msg_hdr) + msg_hdr->length; + if (nextmsg >= data() + hdr()->length) { + assert(data() + hdr()->length == nextmsg); + return (olsr_message_hdr*)0; + } else + return (olsr_message_hdr*)nextmsg; +} + +////////////////////////////////////////////////////////////////////// +// olsr_tc_msg + +olsr_tc_msg::olsr_tc_msg(u_int16_t msg_seq, u_int16_t mssn, + u_int8_t hopcount, u_int32_t originator) { + olsr_tc_hdr *hdr = create(); + hdr->msg_seq = msg_seq; + hdr->mssn = mssn; + hdr->hopcount = hopcount; + hdr->originator = originator; + hdr->reserved1 = 0; + hdr->reserved2 = 0; +} + +olsr_tc_msg::olsr_tc_msg(const u_int8_t *data, int length) + : olsr_part(data, length) { + hdr()->reserved1 = 0; + hdr()->reserved2 = 0; +} + +void olsr_tc_msg::add_mprs_address(u_int32_t addr) { + u_int32_t *addr_ = create(); + *addr_ = addr; +} + +////////////////////////////////////////////////////////////////////// +// olsr_hello_msg_parser + +olsr_hello_msg_parser::olsr_hello_msg_parser(u_int8_t *data, int length) + : data_(data), length_(length), hdr_((olsr_hello_hdr*)data) { + sec_ = 0; + addr_ = 0; +} + +u_int16_t olsr_hello_msg_parser::msg_seq() { + return hdr_->msg_seq; +} + +u_int16_t olsr_hello_msg_parser::mpr_seq() { + return hdr_->mpr_seq; +} + +u_int8_t *olsr_hello_msg_parser::nextsec() { + if (sec_ == 0) { + return data_ + sizeof(olsr_hello_hdr); + } else { + if (!(sec_->length > 0)) throw invalid_packet_format("Link type section size is null!"); + if (sec_->length % 4) throw invalid_packet_format("Link type section size is not a multple of four!"); + u_int8_t *newsec = ((u_int8_t*)sec_) + sec_->length; + if (newsec - data_ > length_) throw invalid_packet_format("Link type section size out of range"); + + return newsec; + } +} + +bool olsr_hello_msg_parser::more_link_types() { + if (nextsec() < data_ + length_) + return true; + else + return false; +} + +link_type_t olsr_hello_msg_parser::next_link_type() { + u_int8_t *next = nextsec(); + sec_ = (olsr_hello_section*)next; + addr_ = (u_int32_t*)(next + sizeof(olsr_hello_section)); + return (link_type_t)sec_->link_type; +} + +bool olsr_hello_msg_parser::more_addresses() { + if (((u_int8_t*)addr_) < (((u_int8_t*)sec_) + sec_->length)) + return true; + else + return false; +} + +u_int32_t olsr_hello_msg_parser::next_address() { + return *(addr_++); +} + +ostream &operator <<(ostream &os, struct olsr_hdr &hdr) { + os << "olsr_hdr={" + << "length=" << hdr.length + << "}"; + return os; +} + +ostream &operator <<(ostream &os, struct olsr_message_hdr &hdr) { + os << "olsr_message_hdr={" + << "type=" << int(hdr.msg_type) + << ",broadcast=" << int(hdr.broadcast) + << ",length=" << int(hdr.length) + << "}"; + return os; +} + +ostream &operator <<(ostream &os, struct olsr_tc_hdr &hdr) { + os << "olsr_tc_hdr {" + << "msg_seq=" << int(hdr.msg_seq) + << ",mssn=" << int(hdr.mssn) + << ",hopcount=" << int(hdr.hopcount) + << ",originator=" << int(hdr.originator) + << "}"; + return os; +} + + +////////////////////////////////////////////////////////////////////// +// olsr_tc_msg_parser + +olsr_tc_msg_parser::olsr_tc_msg_parser(const u_int8_t *thedata, int length) + : olsr_part(thedata, length) { + hdr_ = (olsr_tc_hdr*)data(); + addr_ = (u_int32_t*)(data() + sizeof(olsr_tc_hdr)); +} + +u_int16_t olsr_tc_msg_parser::msg_seq() { + return hdr_->msg_seq; +} + +u_int16_t olsr_tc_msg_parser::mssn() { + return hdr_->mssn; +} + +u_int8_t olsr_tc_msg_parser::hopcount() { + return hdr_->hopcount; +} + +u_int32_t olsr_tc_msg_parser::originator() { + return hdr_->originator; +} + +bool olsr_tc_msg_parser::more_addresses() { + return ((u_int8_t*)addr_ < (data() + size())); +} + +u_int32_t olsr_tc_msg_parser::next_address() { + assert(addr_ < (data() + size())); + return *(addr_++); +} + +olsr_tc_hdr *olsr_tc_msg_parser::hdr() { + return hdr_; +} + +void olsr_show_packet(const u_int8_t *data, int length) { + olsr_packet mypack(data, length); + try { + cout << "*** parsing olsr packet" << endl; + cout << *mypack.hdr() << endl; + olsr_message_hdr *msg = mypack.first_message(); + while (msg != 0) { + cout << *msg << endl; + switch (msg->msg_type) { + case msgtype_hello: + { + cout << "// hello msg" << endl; + olsr_hello_msg_parser p(mypack.message_data(msg), + mypack.message_size(msg)); + while (p.more_link_types()) { + u_int8_t linktype = p.next_link_type(); + cout << " link type " << int(linktype) << endl; + while (p.more_addresses()) { + u_int32_t addr = p.next_address(); + cout << " address " << addr << endl; + } + } + } + break; + case msgtype_tc: + { + cout << "// tc msg" << endl; + olsr_tc_msg_parser p(mypack.message_data(msg), + mypack.message_size(msg)); + cout << *p.hdr() << endl; + + while (p.more_addresses()) { + u_int32_t addr = p.next_address(); + cout << " mprs addr: " << addr << endl; + } + } + + } + msg = mypack.next_message(msg); + } + cerr << "parsing successed" << endl; + } catch (invalid_packet_format e) { + cerr << "parsing failed" << endl; + return; + } +} + diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/packet.hh ns/olsr/packet.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/packet.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/packet.hh Tue Jun 26 14:43:02 2001 @@ -0,0 +1,426 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte +// Hansen, Morten Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __olsr_packet_hh__ +#define __olsr_packet_hh__ + +#include +#include + +#include "types.hh" + +/** + * This file defines the OLSR packet structures and some + * classes usefull for constructing and parsing OLSR packets. + * + * State of this code: Works and is tested. Does not handle invalid + * packets. Does not convert to network byte order. + * + * Copyright (C) 2000, 2001 Lars Christensen and Gitte Hansen. + */ + +////////////////////////////////////////////////////////////////////// +// OLSR packet structures + +// Message types +enum message_type { + msgtype_hello = 1, + msgtype_tc = 2 +}; + +// link type constant +enum link_type_t { + link_undef = 0, + link_asym = 1, + link_sym = 2, + link_mpr = 3, + link_max = 4, + link_seen = 5, +}; + +extern const char *link_type_name[link_max]; + +// header of the entire packet + +struct olsr_hdr { + u_int16_t length; + u_int16_t reserved1; +}; + +extern ostream &operator <<(ostream &os, struct olsr_hdr &hdr); + + +// header of each message within the packet + +enum broadcast_e { NOBROADCAST = 0, + BROADCAST = 1 }; + +struct olsr_message_hdr { + u_int8_t msg_type; + u_int8_t broadcast; + u_int16_t length; // formerly next_message; + + bool is_broadcast() { + return broadcast == BROADCAST; + } +}; +extern ostream &operator <<(ostream &os, struct olsr_message_hdr &hdr); + +// hello message header + +struct olsr_hello_hdr { + u_int16_t msg_seq; + u_int16_t mpr_seq; +}; + +// header of a section within a hello message + +struct olsr_hello_section { + u_int8_t link_type; + u_int8_t reserved1; + u_int16_t length; // formerly next_link_type; +}; + +// header of a tc message + +struct olsr_tc_hdr { + u_int16_t msg_seq; + u_int16_t mssn; + u_int8_t hopcount; + u_int8_t reserved1; + u_int16_t reserved2; + u_int32_t originator; +}; +extern ostream &operator <<(ostream &os, struct olsr_tc_hdr &hdr); + +////////////////////////////////////////////////////////////////////// +// Classes for constructing OLSR packets + +// olsr_base is a wrapper for pointers to allocated data + +class olsr_base { + private: + u_int8_t *data_; + public: + olsr_base(int size) { + data_ = new u_int8_t[size]; + } + ~olsr_base() { + if (data_) + delete[] data_; + } + void swap(olsr_base &base) { + u_int8_t *tmp = data_; + data_ = base.data_; + base.data_ = tmp; + } + u_int8_t *data() const { + return data_; + } +}; + +// olsr_part is a general class for representing sections of an OLSR +// packet + +class olsr_part { +protected: + olsr_base data_; + int capacity_; + int size_; + +public: + olsr_part() : data_(64), capacity_(64), size_(0) { + } + + olsr_part(const u_int8_t *data, int length) : data_(length) { + size_ = length; + capacity_ = length; + memcpy(data_.data(), data, length); + } + + u_int8_t *data() const { + return data_.data(); + } + + virtual ~olsr_part() {} + + void reserve_free(int size) { + int new_capacity = capacity_; + while (new_capacity - size_ < size) + new_capacity *= 2; + if (new_capacity != capacity_) { + olsr_base newbase(new_capacity); + memcpy(newbase.data(), data_.data(), size_); + data_.swap(newbase); + capacity_ = new_capacity; + } + } + + virtual void append(const olsr_part &p) { + reserve_free(p.size_); + memcpy(data()+size_, p.data(), p.size_); + size_ += p.size_; + } + + virtual void append(const u_int8_t *dataptr, int size) { + reserve_free(size); + memcpy(data()+size_, dataptr, size); + size_ += size; + } + + int size() const { + return size_; + } + + // append a type T to the packet, allocating the space + // and returning a pointer to it. + + template + T *create() { + reserve_free(sizeof(T)); + T *ptr = (T*)(data() + size_); + size_ += sizeof(T); + return ptr; + } + + void dumpbin(); +}; + +// excection: throw if an inconsistency is detected in an olsr +// packet + +class invalid_packet_format { +public: + invalid_packet_format(); + invalid_packet_format(const char *st); +}; + + +// olsr_packet represents an entire OLSR packet. + +class olsr_packet : public olsr_part { +public: + olsr_packet() { + olsr_hdr *hdr = create(); + hdr->length = size(); + hdr->reserved1 = 0; + } + + olsr_packet(const u_int8_t *data, int length) : olsr_part(data, length) { + if (hdr()->length != length) { + throw invalid_packet_format("Length field does not match packet size"); + } + } + + // returns a pointer to the header + olsr_hdr *hdr() { + return (olsr_hdr*)data(); + } + + void append(const olsr_part &p) { + olsr_part::append(p); + hdr()->length += p.size(); + } + + void append(const u_int8_t *data, int size) { + olsr_part::append(data, size); + hdr()->length += size; + } + +public: + // append an hello message + void append_hello_msg(const olsr_part &p); + + // append a TC message + void append_tc_msg(const olsr_part &p); + + // Returns a pointer to the first message + olsr_message_hdr *first_message(); + + // return the a pointer to the next message after + // msg_hdr. Returns 0 if there are no more messages + // @precond: msg_hdr is a pointer to a valid olsr_message_hdr, + // previously returned by next_message() or first_message(). + + olsr_message_hdr *next_message(olsr_message_hdr *msg_hdr); + + u_int16_t length() { + return hdr()->length; + } + + // gives a pointer to the data segment of the message + u_int8_t *message_data(olsr_message_hdr *hdr) { + return ((u_int8_t*)hdr) + sizeof(olsr_message_hdr); + } + + // gives the size of the data segment of the message + int message_size(olsr_message_hdr *hdr) { + return hdr->length - sizeof(olsr_message_hdr); + } +}; + +// represent a hello message + +class olsr_hello_msg : public olsr_part { +protected: + int current_sec_offset_; + + olsr_hello_section *current_sec() { + return (olsr_hello_section*)(data() + current_sec_offset_); + } + +public: + olsr_hello_msg(u_int16_t msg_seq, u_int16_t mpr_seq) { + struct olsr_hello_hdr *hdr = create(); + hdr->msg_seq = msg_seq; + hdr->mpr_seq = mpr_seq; + current_sec_offset_ = 0; + } + + void start_link_type(u_int8_t link_type) { + olsr_hello_section *sec_; + sec_ = create(); + current_sec_offset_ = ((u_int8_t*)sec_ - data()); + sec_->link_type = link_type; + sec_->reserved1 = 0; + sec_->length = sizeof(olsr_hello_section); + } + + // appends an address to the current section. start_link_type + // must previously have been called and the most recent + // link_type given to start_link_type() defines where the address + // passed to add_address() goes. + + void add_address(u_int32_t address) { + assert(current_sec_offset_ != 0); + append((u_int8_t*)&address, sizeof(address)); + current_sec()->length += sizeof(address); + } +}; + +/** + * represents a tc message + */ + +class olsr_tc_msg : public olsr_part { +public: + olsr_tc_msg(u_int16_t msg_seq, u_int16_t mssn, + u_int8_t hopcount, u_int32_t originator); + olsr_tc_msg(const u_int8_t *data, int length); + + void add_mprs_address(u_int32_t addr); + + olsr_tc_hdr *hdr() { + return (olsr_tc_hdr*)data(); + } +}; + +////////////////////////////////////////////////////////////////////// +// classes for parsing OLSR messages + +/** + * utility class for parsning hello messages + */ + +class olsr_hello_msg_parser { +public: + olsr_hello_msg_parser(u_int8_t *data, int length); + + // gives the msg-seq number of this hello message + + u_int16_t msg_seq(); + + // returns the mpr-seq number of this hello message + + u_int16_t mpr_seq(); + + // predicate: there are more link type sections + + bool more_link_types(); + + // shifts the internal pointer to the next link type section + // and return the link type enum + // @precond: more_link_types() == true + + link_type_t next_link_type(); + + // predicate: there are more addresses in this section + + bool more_addresses(); + + // returns the next address of this section + // @precond: more_addresses() == null + + u_int32_t next_address(); + +protected: + u_int8_t *data_; + int length_; + + olsr_hello_hdr *hdr_; + olsr_hello_section *sec_; + u_int32_t *addr_; + + u_int8_t *nextsec(); +}; + +/** + * utilitiy class for parsing TC messages + */ + +class olsr_tc_msg_parser : public olsr_part { +public: + olsr_tc_msg_parser(const u_int8_t *data, int length); + + olsr_tc_hdr *hdr(); + + u_int16_t msg_seq(); + u_int16_t mssn(); // MPR Selector [Set] Sequence Number + u_int8_t hopcount(); + u_int32_t originator(); + + // predicate: there are more addresses in this packet + bool more_addresses(); + + // returns the next address + // @precond: more_addresses() == true + u_int32_t next_address(); + + void checkendcondition() { + //assert(addr_ == data_ + length_); + } + +protected: + + olsr_tc_hdr *hdr_; + u_int32_t *addr_; // points to next address in packet +}; + +void olsr_show_packet(const u_int8_t *data, int length); + +#endif __olsr_packet_hh__ diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/perishable.hh ns/olsr/perishable.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/perishable.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/perishable.hh Wed May 9 12:19:51 2001 @@ -0,0 +1,44 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __perishable_hh__ +#define __perishable_hh__ + +#include + +class perishable { + double timeout_; + double max_age_; +public: + perishable(double max_age); + + bool too_old(); + void freshen(); +}; + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/topology.cc ns/olsr/topology.cc --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/topology.cc Thu Jan 1 01:00:00 1970 +++ ns/olsr/topology.cc Wed May 9 12:19:51 2001 @@ -0,0 +1,38 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// topology.cc - OLSR topology table + +#include "config.h" +#include "topology.hh" +#include "constants.hh" +#include "olsrcfg.hh" + +top_selectorentry::top_selectorentry() + : perishable(olsrcfg.topology_hold_time) { +} diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/topology.hh ns/olsr/topology.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/topology.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/topology.hh Wed May 9 12:19:52 2001 @@ -0,0 +1,58 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __topology_hh__ +#define __topology_hh__ + +#include +#include + +// all the information we need to record abour mpr selectors. +class top_selectorentry : public perishable { +public: + top_selectorentry(); +}; + +// Topology entry. Maps MPR selectors to their timeout value and +// records the seq_num for the MPR address in the topology table. + +class top_entry : public map { +public: + top_entry(u_int16_t seq_num) : seq_num_(seq_num) {} + u_int16_t seq_num() { return seq_num_; } +protected: + u_int16_t seq_num_; +}; + +// Topology table. Maps MPR addresses to their MPR selector set -- the +// nodes that have selected it as MPR and thus can be reached through +// that node. (Corresponds to the T_last in the draft) + +typedef map topology; + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/olsr/types.hh ns/olsr/types.hh --- ns-allinone-2.1b7a/ns-2.1b7a/olsr/types.hh Thu Jan 1 01:00:00 1970 +++ ns/olsr/types.hh Wed May 9 12:19:52 2001 @@ -0,0 +1,38 @@ +// Copyright (c) 2000, 2001 Lars Christensen, Gitte Hansen, Morten +// Ernstsen. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote +// products derived from this software without specific prior +// written permission. + +// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +#ifndef __olsr_types_hh__ +#define __olsr_types_hh__ + +#include +#include + +typedef u_int32_t addr_t; +typedef set addr_set_t; + +#endif diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/omni-antenna.cc ns/omni-antenna.cc --- ns-allinone-2.1b7a/ns-2.1b7a/omni-antenna.cc Mon Jan 4 20:59:02 1999 +++ ns/omni-antenna.cc Tue Mar 27 13:21:57 2001 @@ -54,4 +54,8 @@ bind("Gr_", &Gr_); } - +Antenna *OmniAntenna::copy() { + // since the Gt and Gr are constant w.r.t time, we can just return + // this object itself + return this; +} diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/omni-antenna.h ns/omni-antenna.h --- ns-allinone-2.1b7a/ns-2.1b7a/omni-antenna.h Sat Mar 13 04:52:58 1999 +++ ns/omni-antenna.h Tue Mar 27 13:21:58 2001 @@ -45,42 +45,37 @@ class OmniAntenna : public Antenna { public: - OmniAntenna(); + OmniAntenna(); - virtual double getTxGain(double, double, double, double) - // return the gain for a signal to a node at vector dX, dY, dZ - // from the transmitter at wavelength lambda - { - return Gt_; - } - virtual double getRxGain(double, double, double, double) - // return the gain for a signal from a node at vector dX, dY, dZ - // from the receiver at wavelength lambda - { - return Gr_; - } + virtual double getTxGain(double, double, double, double) + // return the gain for a signal to a node at vector dX, dY, dZ + // from the transmitter at wavelength lambda + { + return Gt_; + } + virtual double getRxGain(double, double, double, double) + // return the gain for a signal from a node at vector dX, dY, dZ + // from the receiver at wavelength lambda + { + return Gr_; + } - virtual Antenna * copy() - // return a pointer to a copy of this antenna that will return the - // same thing for get{Rx,Tx}Gain that this one would at this point - // in time. This is needed b/c if a pkt is sent with a directable - // antenna, this antenna may be have been redirected by the time we - // call getTxGain on the copy to determine if the pkt is received. - { - // since the Gt and Gr are constant w.r.t time, we can just return - // this object itself - return this; - } + virtual Antenna * copy(); + // return a pointer to a copy of this antenna that will return the + // same thing for get{Rx,Tx}Gain that this one would at this point + // in time. This is needed b/c if a pkt is sent with a directable + // antenna, this antenna may be have been redirected by the time we + // call getTxGain on the copy to determine if the pkt is received. - virtual void release() - // release a copy created by copy() above - { - // don't do anything - } + virtual void release() + // release a copy created by copy() above + { + // don't do anything + } protected: - double Gt_; // gain of transmitter (db) - double Gr_; // gain of receiver (db) + double Gt_; // gain of transmitter (db) + double Gr_; // gain of receiver (db) }; diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/packet.h ns/packet.h --- ns-allinone-2.1b7a/ns-2.1b7a/packet.h Thu Sep 28 22:19:06 2000 +++ ns/packet.h Thu Mar 1 17:16:25 2001 @@ -110,10 +110,13 @@ /* CMU/Monarch's extnsions */ PT_ARP, PT_MAC, + + /* Ad-Hoc Routing protocols */ PT_TORA, PT_DSR, PT_AODV, PT_IMEP, + PT_OLSR, // RAP packets PT_RAP_DATA, @@ -184,6 +187,7 @@ name_[PT_DSR]= "DSR"; name_[PT_AODV]= "AODV"; name_[PT_IMEP]= "IMEP"; + name_[PT_OLSR]="OLSR"; name_[PT_RAP_DATA] = "rap_data"; name_[PT_RAP_ACK] = "rap_ack"; @@ -260,7 +264,7 @@ } unsigned char* data() { return data_; } - virtual int size() { return datalen_; } + virtual int size() const { return datalen_; } virtual AppData* copy() { return new PacketData(*this); } private: unsigned char* data_; diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/rtqueue.cc ns/rtqueue.cc --- ns-allinone-2.1b7a/ns-2.1b7a/rtqueue.cc Thu Sep 30 22:30:03 1999 +++ ns/rtqueue.cc Tue Jun 26 14:22:29 2001 @@ -144,7 +144,8 @@ Packet *p; while((p = head_) && HDR_CMN(p)->ts_ < CURRENT_TIME) { - assert(p == remove_head()); + Packet *oldhead = remove_head(); + assert(p == oldhead); drop(p, DROP_RTR_QTIMEOUT); } } diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/tcl/lib/ns-lib.tcl ns/tcl/lib/ns-lib.tcl --- ns-allinone-2.1b7a/ns-2.1b7a/tcl/lib/ns-lib.tcl Thu Oct 5 00:46:42 2000 +++ ns/tcl/lib/ns-lib.tcl Thu Mar 1 17:16:25 2001 @@ -485,6 +485,11 @@ AODV { set ragent [$self create-aodv-agent $node] } + + OLSR { + set ragent [$self create-olsr-agent $node] + } + TORA { Simulator set IMEPFlag_ ON set ragent [$self create-tora-agent $node] @@ -627,6 +632,14 @@ $self at 0.0 "$ragent start" ;# start BEACON/HELLO Messages $node set ragent_ $ragent return $ragent +} + +Simulator instproc create-olsr-agent { node } { + # Create OLSR routing agent + set ragent [new Agent/OLSR [$node id]] + $self at 0.0 "$ragent start" ;# start HELLO messages + $node set ragent_ $ragent + return $ragent } Simulator instproc use-newtrace {} { Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-WLtutorial Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-aimd Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-algo-routing Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-cbq Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-cbq-v1 Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-ecn Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-ecn-ack Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-ecn-full Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-energy Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-friendly Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-full Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-greis Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-hier-routing Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-intserv Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-lan Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-links Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-linkstate Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-manual-routing Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-mcache Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-mcast Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-mip Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-mixmode Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-monitor Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-mpls Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-newreno Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-oddBehaviors Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-plm Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-rap Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-rbp Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-realaudio Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-red Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-red-v1 Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-rfc2581 Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-rfc793edu Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-rio Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-sack Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-sack-v1 Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-satellite Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-schedule Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-session Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-simple Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-simultaneous Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-sliding-window Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-srm Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-tcp Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-tcp-init-win Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-tcpOptions Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-tcpVariants Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-testReno Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-v1 Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-vc Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-vegas-v1 Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-webcache Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-webtraf Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-wireless-diffusion Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-wireless-gridkeeper Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-wireless-lan Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-wireless-shadowing Only in ns-allinone-2.1b7a/ns-2.1b7a/tcl/test: test-output-wireless-tdma diff -rPu ns-allinone-2.1b7a/ns-2.1b7a/wireless-phy.cc ns/wireless-phy.cc --- ns-allinone-2.1b7a/ns-2.1b7a/wireless-phy.cc Wed Oct 18 03:35:42 2000 +++ ns/wireless-phy.cc Tue Mar 27 13:21:58 2001 @@ -102,6 +102,7 @@ lambda_ = SPEED_OF_LIGHT / freq_; node_ = 0; + ant_ = 0; propagation_ = 0; modulation_ = 0; @@ -261,7 +262,10 @@ /* * Stamp the packet with the interface arguments */ - p->txinfo_.stamp(mobilenode(), ant_->copy(), Pt_, lambda_); + MobileNode *n = mobilenode(); + Antenna *ant = ant_->copy(); + PacketStamp &stmp = p->txinfo_; + stmp.stamp(n, ant, Pt_, lambda_); // Send the packet channel_->recv(p, this);