lib/obamp/src/obamp.h
author Saverio Proto <zioproto@gmail.com>
Mon Aug 31 16:17:05 2009 +0200 (2 years ago)
changeset 2447 8e7887c1247f
child 2448ce6de529ee41
permissions -rw-r--r--
Adding the first implementation of the OBAMP plugin. See README file for documentation.
     1 
     2 /*
     3 OLSR OBAMP plugin.
     4 Written by Saverio Proto <zioproto@gmail.com> and Claudio Pisa <clauz@ninux.org>.
     5 
     6     This file is part of OLSR OBAMP PLUGIN.
     7 
     8     The OLSR OBAMP PLUGIN is free software: you can redistribute it and/or modify
     9     it under the terms of the GNU General Public License as published by
    10     the Free Software Foundation, either version 3 of the License, or
    11     (at your option) any later version.
    12 
    13     The OLSR OBAMP PLUGIN is distributed in the hope that it will be useful,
    14     but WITHOUT ANY WARRANTY; without even the implied warranty of
    15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16     GNU General Public License for more details.
    17 
    18     You should have received a copy of the GNU General Public License
    19     along with the OLSR OBAMP PLUGIN.  If not, see <http://www.gnu.org/licenses/>.
    20 
    21  */
    22 
    23 
    24 #ifndef _OBAMP_OBAMP_H
    25 #define _OBAMP_OBAMP_H
    26 
    27 #include "list.h"
    28 
    29 #include "plugin.h"             /* union set_plugin_parameter_addon */
    30 
    31 #include "parser.h"
    32 
    33 #define MESSAGE_TYPE 		133 			//TODO: check if this number is ok
    34 #define PARSER_TYPE		MESSAGE_TYPE
    35 #define EMISSION_INTERVAL       10      		/* seconds */
    36 #define EMISSION_JITTER         25      		/* percent */
    37 #define OBAMP_VALID_TIME	1800   			/* seconds */
    38 
    39 /* OBAMP plugin data */
    40 #define PLUGIN_NAME 		"OLSRD OBAMP plugin"
    41 #define PLUGIN_NAME_SHORT 	"OLSRD OBAMP"
    42 #define PLUGIN_VERSION 		"1.0.0 (" __DATE__ " " __TIME__ ")"
    43 #define PLUGIN_COPYRIGHT 	"  (C) Ninux.org"
    44 #define PLUGIN_AUTHOR 		"  Saverio Proto (zioproto@gmail.com)"
    45 #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION "\n" PLUGIN_COPYRIGHT "\n" PLUGIN_AUTHOR
    46 #define PLUGIN_INTERFACE_VERSION 5
    47 
    48 #define PLUGIN_DESCR 		"OBAMP"
    49 
    50 #define OBAMP_JITTER         	25 			/* percent */
    51 #define OBAMP_ALIVE_EIVAL    	5
    52 #define OBAMP_MESH_CREATE_IVAL	5 			//Seconds
    53 #define OBAMP_TREE_CREATE_IVAL	10 			//seconds
    54 #define TREE_HEARTBEAT    	25 			//seconds
    55 #define OBAMP_OUTER_TREE_CREATE_IVAL    30 		//seconds
    56 #define _MESH_LOCK_		10			//seconds
    57 
    58 #define _Texpire_		15			 //time in seconds before expire a neighbor
    59 #define _Texpire_timer_		1			//time in seconds to parse the list decrement and purge
    60 
    61 
    62 /*OBAMP Protocol MESSAGE IDs */
    63 
    64 #define OBAMP_DATA 		0
    65 #define OBAMP_HELLO 		1 
    66 #define OBAMP_TREECREATE 	2 
    67 #define OBAMP_ALIVE 		3
    68 #define OBAMP_TREE_REQ 		4
    69 #define OBAMP_TREE_ACK 		5
    70 
    71 #define OBAMP_SIGNALLING_PORT 	6226
    72 
    73 
    74 
    75 extern struct ObampNodeState* myState; //Internal state of the running OBAMP node
    76 
    77 /* Forward declaration of OLSR interface type */
    78 struct interface;
    79 
    80 union olsr_ip_addr *MainAddressOf(union olsr_ip_addr *ip);
    81 
    82 void ObampSignalling(int sd, void *x, unsigned int y);
    83 
    84 //Gets packets from sniffing interfaces, checks if are multicast, and pushes them to OBAMP tree links
    85 void EncapFlowInObamp(int sd, void * x, unsigned int y);
    86 
    87 //Used to add Sniffing Interfaces read from config file to the list
    88 int AddObampSniffingIf(const char *ifName, void *data, set_plugin_parameter_addon addon);
    89 
    90 
    91 int InitOBAMP(void);
    92 int PreInitOBAMP(void);
    93 void CloseOBAMP(void);
    94 
    95 void olsr_obamp_gen(unsigned char *packet, int len);
    96 
    97 void obamp_hello_gen(void *para);
    98 void obamp_alive_gen(void *para);
    99 void purge_nodes(void *para);
   100 void mesh_create(void *para);
   101 void tree_create(void *para);
   102 void outer_tree_create(void *para);
   103 
   104 int addObampNode4(struct in_addr * ipv4, u_int8_t status);
   105 
   106 
   107 /* Parser function to register with the scheduler */
   108 void olsr_parser(union olsr_message *, struct interface *, union olsr_ip_addr *, enum duplicate_status);
   109 
   110 //Struct to describe the other OBAMP nodes in the mesh network
   111 struct ObampNode {
   112 
   113 	union olsr_ip_addr neighbor_ip_addr; //IP address
   114 
   115 	int isMesh; //The consider the path from us to this OBAMP node as an overlay mesh link
   116 	int wasMesh;
   117 	int outerTreeLink; //I'm using this OBAMP node as an anchor
   118 	int isTree;//it identifies if it is a link of tree
   119 	int MeshLock; //Is mesh because requested from neighbor	with hello messages
   120 
   121 	u_int8_t status; //indicates if this OBAMP node has at least a tree link
   122 	
   123 	int Texpire;// TTL to softstate expire
   124 
   125 	u_int8_t DataSeqNumber;
   126 
   127   	struct list_head list;
   128 };
   129 
   130 //Interfaces of the router not talking OLSR, where we capture the multicast traffic
   131 struct ObampSniffingIf {
   132 
   133 int skd; 		//Socket descriptor
   134 char ifName[16]; 	//Interface name
   135 struct list_head list;
   136 
   137 };
   138 
   139 
   140 //Internal State of the OBAMP NoDE
   141 struct ObampNodeState {
   142     
   143     union olsr_ip_addr myipaddr; //IP ADDRESS
   144     union olsr_ip_addr CoreAddress; //CORE IP ADDRESS
   145 
   146     int iamcore; //Indicates if I'm the core
   147     
   148     u_int8_t TreeCreateSequenceNumber;
   149     u_int8_t tree_req_sn;
   150     u_int8_t DataSequenceNumber;
   151 
   152     union olsr_ip_addr ParentId;	//Tree link towards the core
   153     union olsr_ip_addr OldParentId;
   154 
   155     /*
   156 	TTL to check if I'm receiving tree_create messages from core
   157 	if this expires there is a problem with the spanning tree
   158 
   159 	*/
   160     int TreeHeartBeat;	
   161 };
   162 
   163 // OBAMP message types
   164 
   165 
   166 struct OBAMP_data_message {
   167 
   168 u_int8_t MessageID;
   169 union olsr_ip_addr router_id;
   170 union olsr_ip_addr last_hop;
   171 u_int8_t SequenceNumber;
   172 union olsr_ip_addr CoreAddress;
   173 u_int8_t datalen;
   174 unsigned char data[1280]; //TODO:fix me
   175 
   176 };
   177 
   178 struct OBAMP_tree_create {
   179 
   180 u_int8_t MessageID;
   181 union olsr_ip_addr router_id;
   182 u_int8_t SequenceNumber;
   183 union olsr_ip_addr CoreAddress;
   184 
   185 };
   186 
   187 struct OBAMP_tree_link_req {
   188 
   189 u_int8_t MessageID;
   190 union olsr_ip_addr router_id;
   191 u_int8_t SequenceNumber;
   192 union olsr_ip_addr CoreAddress;
   193 };
   194 
   195 struct OBAMP_tree_link_ack {
   196 
   197 u_int8_t MessageID;
   198 union olsr_ip_addr router_id;
   199 u_int8_t SequenceNumber;
   200 union olsr_ip_addr CoreAddress;
   201 };
   202 
   203 
   204 struct OBAMP_hello {
   205 
   206 u_int8_t MessageID;
   207 union olsr_ip_addr router_id;
   208 u_int8_t HelloSequenceNumber;
   209 union olsr_ip_addr CoreAddress;
   210 
   211 };
   212 
   213 struct OBAMP_alive {
   214 
   215 u_int8_t MessageID;
   216 u_int8_t status;
   217 u_int32_t CoreAddress;
   218 //REMEMBER:Pad to 4 bytes this is a OLSR message
   219 
   220 };
   221 
   222 #endif /* _OBAMP_OBAMP_H */
   223