lib/obamp/src/obamp.h
changeset 2447 8e7887c1247f
child 2448ce6de529ee41
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/obamp/src/obamp.h	Mon Aug 31 16:17:05 2009 +0200
     1.3 @@ -0,0 +1,223 @@
     1.4 +
     1.5 +/*
     1.6 +OLSR OBAMP plugin.
     1.7 +Written by Saverio Proto <zioproto@gmail.com> and Claudio Pisa <clauz@ninux.org>.
     1.8 +
     1.9 +    This file is part of OLSR OBAMP PLUGIN.
    1.10 +
    1.11 +    The OLSR OBAMP PLUGIN is free software: you can redistribute it and/or modify
    1.12 +    it under the terms of the GNU General Public License as published by
    1.13 +    the Free Software Foundation, either version 3 of the License, or
    1.14 +    (at your option) any later version.
    1.15 +
    1.16 +    The OLSR OBAMP PLUGIN is distributed in the hope that it will be useful,
    1.17 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.18 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.19 +    GNU General Public License for more details.
    1.20 +
    1.21 +    You should have received a copy of the GNU General Public License
    1.22 +    along with the OLSR OBAMP PLUGIN.  If not, see <http://www.gnu.org/licenses/>.
    1.23 +
    1.24 + */
    1.25 +
    1.26 +
    1.27 +#ifndef _OBAMP_OBAMP_H
    1.28 +#define _OBAMP_OBAMP_H
    1.29 +
    1.30 +#include "list.h"
    1.31 +
    1.32 +#include "plugin.h"             /* union set_plugin_parameter_addon */
    1.33 +
    1.34 +#include "parser.h"
    1.35 +
    1.36 +#define MESSAGE_TYPE 		133 			//TODO: check if this number is ok
    1.37 +#define PARSER_TYPE		MESSAGE_TYPE
    1.38 +#define EMISSION_INTERVAL       10      		/* seconds */
    1.39 +#define EMISSION_JITTER         25      		/* percent */
    1.40 +#define OBAMP_VALID_TIME	1800   			/* seconds */
    1.41 +
    1.42 +/* OBAMP plugin data */
    1.43 +#define PLUGIN_NAME 		"OLSRD OBAMP plugin"
    1.44 +#define PLUGIN_NAME_SHORT 	"OLSRD OBAMP"
    1.45 +#define PLUGIN_VERSION 		"1.0.0 (" __DATE__ " " __TIME__ ")"
    1.46 +#define PLUGIN_COPYRIGHT 	"  (C) Ninux.org"
    1.47 +#define PLUGIN_AUTHOR 		"  Saverio Proto (zioproto@gmail.com)"
    1.48 +#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION "\n" PLUGIN_COPYRIGHT "\n" PLUGIN_AUTHOR
    1.49 +#define PLUGIN_INTERFACE_VERSION 5
    1.50 +
    1.51 +#define PLUGIN_DESCR 		"OBAMP"
    1.52 +
    1.53 +#define OBAMP_JITTER         	25 			/* percent */
    1.54 +#define OBAMP_ALIVE_EIVAL    	5
    1.55 +#define OBAMP_MESH_CREATE_IVAL	5 			//Seconds
    1.56 +#define OBAMP_TREE_CREATE_IVAL	10 			//seconds
    1.57 +#define TREE_HEARTBEAT    	25 			//seconds
    1.58 +#define OBAMP_OUTER_TREE_CREATE_IVAL    30 		//seconds
    1.59 +#define _MESH_LOCK_		10			//seconds
    1.60 +
    1.61 +#define _Texpire_		15			 //time in seconds before expire a neighbor
    1.62 +#define _Texpire_timer_		1			//time in seconds to parse the list decrement and purge
    1.63 +
    1.64 +
    1.65 +/*OBAMP Protocol MESSAGE IDs */
    1.66 +
    1.67 +#define OBAMP_DATA 		0
    1.68 +#define OBAMP_HELLO 		1 
    1.69 +#define OBAMP_TREECREATE 	2 
    1.70 +#define OBAMP_ALIVE 		3
    1.71 +#define OBAMP_TREE_REQ 		4
    1.72 +#define OBAMP_TREE_ACK 		5
    1.73 +
    1.74 +#define OBAMP_SIGNALLING_PORT 	6226
    1.75 +
    1.76 +
    1.77 +
    1.78 +extern struct ObampNodeState* myState; //Internal state of the running OBAMP node
    1.79 +
    1.80 +/* Forward declaration of OLSR interface type */
    1.81 +struct interface;
    1.82 +
    1.83 +union olsr_ip_addr *MainAddressOf(union olsr_ip_addr *ip);
    1.84 +
    1.85 +void ObampSignalling(int sd, void *x, unsigned int y);
    1.86 +
    1.87 +//Gets packets from sniffing interfaces, checks if are multicast, and pushes them to OBAMP tree links
    1.88 +void EncapFlowInObamp(int sd, void * x, unsigned int y);
    1.89 +
    1.90 +//Used to add Sniffing Interfaces read from config file to the list
    1.91 +int AddObampSniffingIf(const char *ifName, void *data, set_plugin_parameter_addon addon);
    1.92 +
    1.93 +
    1.94 +int InitOBAMP(void);
    1.95 +int PreInitOBAMP(void);
    1.96 +void CloseOBAMP(void);
    1.97 +
    1.98 +void olsr_obamp_gen(unsigned char *packet, int len);
    1.99 +
   1.100 +void obamp_hello_gen(void *para);
   1.101 +void obamp_alive_gen(void *para);
   1.102 +void purge_nodes(void *para);
   1.103 +void mesh_create(void *para);
   1.104 +void tree_create(void *para);
   1.105 +void outer_tree_create(void *para);
   1.106 +
   1.107 +int addObampNode4(struct in_addr * ipv4, u_int8_t status);
   1.108 +
   1.109 +
   1.110 +/* Parser function to register with the scheduler */
   1.111 +void olsr_parser(union olsr_message *, struct interface *, union olsr_ip_addr *, enum duplicate_status);
   1.112 +
   1.113 +//Struct to describe the other OBAMP nodes in the mesh network
   1.114 +struct ObampNode {
   1.115 +
   1.116 +	union olsr_ip_addr neighbor_ip_addr; //IP address
   1.117 +
   1.118 +	int isMesh; //The consider the path from us to this OBAMP node as an overlay mesh link
   1.119 +	int wasMesh;
   1.120 +	int outerTreeLink; //I'm using this OBAMP node as an anchor
   1.121 +	int isTree;//it identifies if it is a link of tree
   1.122 +	int MeshLock; //Is mesh because requested from neighbor	with hello messages
   1.123 +
   1.124 +	u_int8_t status; //indicates if this OBAMP node has at least a tree link
   1.125 +	
   1.126 +	int Texpire;// TTL to softstate expire
   1.127 +
   1.128 +	u_int8_t DataSeqNumber;
   1.129 +
   1.130 +  	struct list_head list;
   1.131 +};
   1.132 +
   1.133 +//Interfaces of the router not talking OLSR, where we capture the multicast traffic
   1.134 +struct ObampSniffingIf {
   1.135 +
   1.136 +int skd; 		//Socket descriptor
   1.137 +char ifName[16]; 	//Interface name
   1.138 +struct list_head list;
   1.139 +
   1.140 +};
   1.141 +
   1.142 +
   1.143 +//Internal State of the OBAMP NoDE
   1.144 +struct ObampNodeState {
   1.145 +    
   1.146 +    union olsr_ip_addr myipaddr; //IP ADDRESS
   1.147 +    union olsr_ip_addr CoreAddress; //CORE IP ADDRESS
   1.148 +
   1.149 +    int iamcore; //Indicates if I'm the core
   1.150 +    
   1.151 +    u_int8_t TreeCreateSequenceNumber;
   1.152 +    u_int8_t tree_req_sn;
   1.153 +    u_int8_t DataSequenceNumber;
   1.154 +
   1.155 +    union olsr_ip_addr ParentId;	//Tree link towards the core
   1.156 +    union olsr_ip_addr OldParentId;
   1.157 +
   1.158 +    /*
   1.159 +	TTL to check if I'm receiving tree_create messages from core
   1.160 +	if this expires there is a problem with the spanning tree
   1.161 +
   1.162 +	*/
   1.163 +    int TreeHeartBeat;	
   1.164 +};
   1.165 +
   1.166 +// OBAMP message types
   1.167 +
   1.168 +
   1.169 +struct OBAMP_data_message {
   1.170 +
   1.171 +u_int8_t MessageID;
   1.172 +union olsr_ip_addr router_id;
   1.173 +union olsr_ip_addr last_hop;
   1.174 +u_int8_t SequenceNumber;
   1.175 +union olsr_ip_addr CoreAddress;
   1.176 +u_int8_t datalen;
   1.177 +unsigned char data[1280]; //TODO:fix me
   1.178 +
   1.179 +};
   1.180 +
   1.181 +struct OBAMP_tree_create {
   1.182 +
   1.183 +u_int8_t MessageID;
   1.184 +union olsr_ip_addr router_id;
   1.185 +u_int8_t SequenceNumber;
   1.186 +union olsr_ip_addr CoreAddress;
   1.187 +
   1.188 +};
   1.189 +
   1.190 +struct OBAMP_tree_link_req {
   1.191 +
   1.192 +u_int8_t MessageID;
   1.193 +union olsr_ip_addr router_id;
   1.194 +u_int8_t SequenceNumber;
   1.195 +union olsr_ip_addr CoreAddress;
   1.196 +};
   1.197 +
   1.198 +struct OBAMP_tree_link_ack {
   1.199 +
   1.200 +u_int8_t MessageID;
   1.201 +union olsr_ip_addr router_id;
   1.202 +u_int8_t SequenceNumber;
   1.203 +union olsr_ip_addr CoreAddress;
   1.204 +};
   1.205 +
   1.206 +
   1.207 +struct OBAMP_hello {
   1.208 +
   1.209 +u_int8_t MessageID;
   1.210 +union olsr_ip_addr router_id;
   1.211 +u_int8_t HelloSequenceNumber;
   1.212 +union olsr_ip_addr CoreAddress;
   1.213 +
   1.214 +};
   1.215 +
   1.216 +struct OBAMP_alive {
   1.217 +
   1.218 +u_int8_t MessageID;
   1.219 +u_int8_t status;
   1.220 +u_int32_t CoreAddress;
   1.221 +//REMEMBER:Pad to 4 bytes this is a OLSR message
   1.222 +
   1.223 +};
   1.224 +
   1.225 +#endif /* _OBAMP_OBAMP_H */
   1.226 +