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