/*
Copyright (c) 1997, 1998 Carnegie Mellon University. All Rights
Reserved.
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 name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
The Zigbee code developed by Hu Yaxin, SJTU. The work was done in Win32+Cygwin.
*/
#ifndef __zigbee_h__
#define __zigbee_h__
//#include <agent.h>
//#include <packet.h>
//#include <sys/types.h>
//#include <cmu/list.h>
//#include <scheduler.h>
#include <cmu-trace.h>
#include <priqueue.h>
#include <zigbee/zigbee_rtable.h>
#include <zigbee/zigbee_rqueue.h>
#include <classifier/classifier-port.h>
/*
Allows local repair of routes
*/
#define ZIGBEE_LOCAL_REPAIR
/*
Allows ZIGBEE to use link-layer (802.11) feedback in determining when
links are up/down.
*/
#define ZIGBEE_LINK_LAYER_DETECTION
/*
Causes ZIGBEE to apply a "smoothing" function to the link layer feedback
that is generated by 802.11. In essence, it requires that RT_MAX_ERROR
errors occurs within a window of RT_MAX_ERROR_TIME before the link
is considered bad.
*/
#define ZIGBEE_USE_LL_METRIC
/*
Only applies if ZIGBEE_USE_LL_METRIC is defined.
Causes ZIGBEE to apply omniscient knowledge to the feedback received
from 802.11. This may be flawed, because it does not account for
congestion.
*/
//#define ZIGBEE_USE_GOD_FEEDBACK
class ZIGBEE;
#define MY_ROUTE_TIMEOUT 10 // 100 seconds
#define ACTIVE_ROUTE_TIMEOUT 10 // 50 seconds
#define REV_ROUTE_LIFE 6 // 5 seconds
#define BCAST_ID_SAVE 6 // 3 seconds
// No. of times to do network-wide search before timing out for
// MAX_RREQ_TIMEOUT sec.
#define RREQ_RETRIES 3
// timeout after doing network-wide search RREQ_RETRIES times
#define MAX_RREQ_TIMEOUT 10.0 //sec
/* Various constants used for the expanding ring search */
#define TTL_START 5
#define TTL_THRESHOLD 7
#define TTL_INCREMENT 2
// This should be somewhat related to arp timeout
#define NODE_TRAVERSAL_TIME 0.03 // 30 ms
#define LOCAL_REPAIR_WAIT_TIME 0.15 //sec
// Should be set by the user using best guess (conservative)
#define NETWORK_DIAMETER 30 // 30 hops
// Must be larger than the time difference between a node propagates a route
// request and gets the route reply back.
//#define RREP_WAIT_TIME (3 * NODE_TRAVERSAL_TIME * NETWORK_DIAMETER) // ms
//#define RREP_WAIT_TIME (2 * REV_ROUTE_LIFE) // seconds
#define RREP_WAIT_TIME 1.0 // sec
#define ID_NOT_FOUND 0x00
#define ID_FOUND 0x01
//#define INFINITY 0xff
// The followings are used for the forward() function. Controls pacing.
#define DELAY 1.0 // random delay
#define NO_DELAY -1.0 // no delay
// think it should be 30 ms
#define ARP_DELAY 0.01 // fixed delay to keep arp happy
#define HELLO_INTERVAL 1 // 1000 ms
#define ALLOWED_HELLO_LOSS 3 // packets
#define BAD_LINK_LIFETIME 3 // 3000 ms
#define MaxHelloInterval (1.25 * HELLO_INTERVAL)
#define MinHelloInterval (0.75 * HELLO_INTERVAL)
/*
Timers (Broadcast ID, Hello, Neighbor Cache, Route Cache)
*/
class ZigbeeBroadcastTimer : public Handler {
public:
ZigbeeBroadcastTimer(ZIGBEE* a) : agent(a) {}
void handle(Event*);
private:
ZIGBEE *agent;
Event intr;
};
class ZigbeeHelloTimer : public Handler {
public:
ZigbeeHelloTimer(ZIGBEE* a) : agent(a) {}
void handle(Event*);
private:
ZIGBEE *agent;
Event intr;
};
class ZigbeeNeighborTimer : public Handler {
public:
ZigbeeNeighborTimer(ZIGBEE* a) : agent(a) {}
void handle(Event*);
private:
ZIGBEE *agent;
Event intr;
};
class ZigbeeRouteCacheTimer : public Handler {
public:
ZigbeeRouteCacheTimer(ZIGBEE* a) : agent(a) {}
void handle(Event*);
private:
ZIGBEE *agent;
Event intr;
};
class ZigbeeLocalRepairTimer : public Handler {
public:
ZigbeeLocalRepairTimer(ZIGBEE* a) : agent(a) {}
void handle(Event*);
private:
ZIGBEE *agent;
Event intr;
};
/*
Broadcast ID Cache
*/
class BroadcastID {
friend class ZIGBEE;
public:
BroadcastID(nsaddr_t i, u_int32_t b) { src = i; id = b; }
protected:
LIST_ENTRY(BroadcastID) link;
nsaddr_t src;
u_int32_t id;
double expire; // now + BCAST_ID_SAVE s
};
LIST_HEAD(zigbee_bcache, BroadcastID);
/*
The Routing Agent
*/
class ZIGBEE: public Agent {
/*
* make some friends first
*/
friend class zigbee_rt_entry;
friend class ZigbeeBroadcastTimer;
friend class ZigbeeHelloTimer;
friend class ZigbeeNeighborTimer;
friend class ZigbeeRouteCacheTimer;
friend class ZigbeeLocalRepairTimer;
public:
ZIGBEE(nsaddr_t id);
void recv(Packet *p, Handler *);
protected:
int command(int, const char *const *);
int initialized() { return 1 && target_; }
/*
* Route Table Management
*/
void rt_resolve(Packet *p);
void rt_update(zigbee_rt_entry *rt, nsaddr_t nexthop,
double expire_time);
void rt_down(zigbee_rt_entry *rt);
void local_rt_repair(zigbee_rt_entry *rt, Packet *p);
public:
void rt_ll_failed(Packet *p);
void handle_link_failure(nsaddr_t id);
protected:
void rt_purge(void);
void enque(zigbee_rt_entry *rt, Packet *p);
Packet* deque(zigbee_rt_entry *rt);
/*
* Neighbor Management
*/
void nb_insert(nsaddr_t id);
ZIGBEE_Neighbor* nb_lookup(nsaddr_t id);
void nb_delete(nsaddr_t id);
void nb_purge(void);
/*
* Broadcast ID Management
*/
void id_insert(nsaddr_t id, u_int32_t bid);
bool id_lookup(nsaddr_t id, u_int32_t bid);
void id_purge(void);
/*
* Packet TX Routines
*/
void forward(zigbee_rt_entry *rt, Packet *p, double delay);
void sendHello(void);
void sendRequest(nsaddr_t dst);
void sendReply(nsaddr_t ipdst, nsaddr_t rpdst,
u_int32_t lifetime, double timestamp);
void sendError(Packet *p, bool jitter = true);
/*
* Packet RX Routines
*/
void recvZIGBEE(Packet *p);
void recvHello(Packet *p);
void recvRequest(Packet *p);
void
aodvjr.rar_AODVjr_AODVjr n_aodvjr ns2_ns2 aodvjr
版权申诉
2 浏览量
2022-09-23
07:46:06
上传
评论
收藏 25KB RAR 举报
APei
- 粉丝: 64
- 资源: 1万+
最新资源
- career.it.signals-systems信号与系统
- 面向计算机视觉的基础库,支持Linux、Windows及MacOS平台 提供了众多功能,包括基于PyTorch的通用训练框架等
- 基于LQR实现的车辆轨迹跟踪matlab源码+项目说明+超详细注释(高分项目)
- 视2.css
- Android图片处理工具类,包括: 图片查看、照片墙、bitmap转存、圆角、剪切、图片加载缓存、图片压缩等
- 甘豆影评React Native版
- 百度地图,显示闸站分布,以及切换闸站位置,上传闸站图片信息的cordova插件,包含百度地图和百度定位库文件
- 基于合泰单片机的智能夹球小车(esp8266代码+k210代码+合泰单片机代码)
- 一个天气查询的安卓APP
- 基于CC2530+DHT11温湿度传感器实现物联网多传感器火灾报警系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈