ROFL-pipeline  v0.6.0dev
physical_switch.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef __PHYSICAL_SWITCH_H__
6 #define __PHYSICAL_SWITCH_H__
7 
8 #include <stdlib.h>
9 #include <string.h>
10 #include "rofl.h"
11 #include "openflow/of_switch.h"
12 #include "switch_port.h"
13 #include "monitoring.h"
14 #include "platform/lock.h"
15 
95 #ifndef PHYSICAL_SWITCH_MAX_LS
96 
100  #define PHYSICAL_SWITCH_MAX_LS 64
101 #endif
102 
103 #ifndef PHYSICAL_SWITCH_MAX_NUM_PHY_PORTS
104 
108  #define PHYSICAL_SWITCH_MAX_NUM_PHY_PORTS 1024
109 #endif
110 
111 #ifndef PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS
112 
116  #define PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS 256
117 #endif
118 
119 #ifndef PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS
120 
124  #define PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS 32
125 #endif
126 
127 #define PHYSICAL_SWITCH_MAX_NUM_META_PORTS 8
128 
129 //Opaque platform state (to be used, maybe, for platform hooks).
130 //Currently unused
131 typedef void platform_physical_switch_state_t;
132 
133 
138 
143 
148 
153 typedef struct physical_switch{
154 
155  /*
156  * List of all logical switches in the system
157  */
158  unsigned int num_of_logical_switches;
159  of_switch_t* logical_switches[PHYSICAL_SWITCH_MAX_LS];
160 
161  /*
162  * Ports
163  */
164  //physical: index is the physical port of the platform.
166 
167  //tunnel ports
168  switch_port_t* tunnel_ports[PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS]; //Not used yet
169 
170  //virtual ports (which are not tunnel)
171  switch_port_t* virtual_ports[PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS]; //Not used yet
172 
173  //meta ports (esoteric ports). This is NOT an array of pointers!
174  switch_port_t meta_ports[PHYSICAL_SWITCH_MAX_NUM_META_PORTS];
175 
176  //Monitoring data
177  monitoring_state_t monitoring;
178 
179  /*
180  * Other state
181  */
182  //Mutex
183  platform_mutex_t* mutex;
184 
185  //Opaque platform specific extra state
186  platform_physical_switch_state_t* platform_state;
188 
192 typedef struct dpid_list{
193 
194  //Number of ports in the port list
195  unsigned int num_of_lsis;
196 
197  //dpids
198  uint64_t* dpids;
199 }dpid_list_t;
200 
201 //C++ extern C
202 ROFL_BEGIN_DECLS
203 
204 
205 //
206 //
207 // Physical switch mgmt
208 //
209 //
210 
215 rofl_result_t physical_switch_init(void);
216 
224 
225 //Only used in multi-process deployments (with shared memory)
226 void __set_physical_switch(physical_switch_t* sw);
227 
235 void physical_switch_destroy(void);
236 
237 
238 //
239 //
240 // Logical switch management
241 //
242 //
243 
251 of_switch_t** physical_switch_get_logical_switches(unsigned int* max_switches);
252 
263 
269 rofl_result_t physical_switch_remove_logical_switch_by_dpid(const uint64_t dpid);
270 
276 
277 //Getters
283 
289 
290 //
291 //
292 // Port management routines
293 //
294 //
295 
303 
311 switch_port_t** physical_switch_get_physical_ports(unsigned int* max_ports);
312 
320 switch_port_t** physical_switch_get_virtual_ports(unsigned int* max_ports);
321 
329 switch_port_t** physical_switch_get_tunnel_ports(unsigned int* max_ports);
330 
342 rofl_result_t physical_switch_add_port(switch_port_t* port);
343 
353 rofl_result_t physical_switch_remove_port(const char* name);
354 
355 
356 //
357 //
358 // Logical switches port management
359 //
360 //
361 
373 switch_port_t* physical_switch_get_port_by_num(const uint64_t dpid, unsigned int port_num);
374 
375 
381 rofl_result_t get_logical_switch_ports(of_switch_t* sw, logical_switch_port_t** ports, unsigned int* num_of_ports, unsigned int* logical_sw_max_ports);
382 
388 rofl_result_t physical_switch_attach_port_to_logical_switch(switch_port_t* port, of_switch_t* sw, unsigned int* port_num);
389 
400 rofl_result_t physical_switch_attach_port_to_logical_switch_at_port_num(switch_port_t* port, of_switch_t* sw, unsigned int port_num);
401 
406 rofl_result_t physical_switch_detach_port_num_from_logical_switch(unsigned int port_num, of_switch_t* sw);
407 
413 
419 
420 
421 
422 //
423 // Monitoring
424 //
431 
432  if(psw)
433  return &psw->monitoring;
434  return NULL;
435 }
436 
437 //
438 // Snapshots
439 //
440 
441 //Ports
449 
457 
458 
459 //LSIs
460 
465 
470 void dpid_list_destroy(dpid_list_t* list);
471 
477 
478 
479 //
480 // Other
481 //
482 
483 //This should not be used in general. Generates the matching algorithm list
484 void __physical_switch_generate_matching_algorithm_list(void);
485 
486 
487 //C++ extern C
488 ROFL_END_DECLS
489 
490 #endif //PHYSICAL_SWITCH
#define PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS
Maximum number of virtual ports.
OpenFlow-enabled switch abstraction (version-indepedent part).
Definition: of_switch.h:55
Defines the locking interface used by the library. The user of the library MUST provide an implementa...
struct dpid_list dpid_list_t
List of dpids (snapshots)
rofl_result_t physical_switch_add_logical_switch(of_switch_t *sw)
Add a logical switch to the pool.
ROFL_BEGIN_DECLS rofl_result_t physical_switch_init(void)
Initializes the physical switch.
rofl_result_t physical_switch_detach_all_ports_from_logical_switch(of_switch_t *sw)
Detaches all the ports from the logical switch.
rofl_result_t get_logical_switch_ports(of_switch_t *sw, logical_switch_port_t **ports, unsigned int *num_of_ports, unsigned int *logical_sw_max_ports)
Retrieve the physical port list.
of_switch_t ** physical_switch_get_logical_switches(unsigned int *max_switches)
Retrieves the list of logical switches within the logical switch.
of_switch_snapshot_t * physical_switch_get_logical_switch_snapshot(const uint64_t dpid)
Generates a snapshot of the current running state of a LSI, which can be safely read and iterated ove...
rofl_result_t physical_switch_remove_logical_switch(of_switch_t *sw)
Attemps to remove AND destroy a previously added logical switch from the pool.
Container of the monitoring state.
Definition: monitoring.h:168
Port abstraction and API.
void dpid_list_destroy(dpid_list_t *list)
Destroy a previously generated list of dpids.
switch_port_t ** physical_switch_get_virtual_ports(unsigned int *max_ports)
Get the reference to the virtual ports.
switch_port_t * all_meta_port
Special meta port: ALL.
#define PHYSICAL_SWITCH_MAX_NUM_PHY_PORTS
Maximum number of phyisical ports.
rofl_result_t physical_switch_remove_port(const char *name)
Removes and destroys a port from the physical_switch pool referenced by its nameAttempts to remove AN...
rofl_result_t physical_switch_attach_port_to_logical_switch_at_port_num(switch_port_t *port, of_switch_t *sw, unsigned int port_num)
Attaches port to logical switch at port number port_num.
rofl_result_t physical_switch_attach_port_to_logical_switch(switch_port_t *port, of_switch_t *sw, unsigned int *port_num)
Attaches port to logical switch.
#define PHYSICAL_SWITCH_MAX_LS
Maximum number of logical switches that can be instantiated.
rofl_result_t physical_switch_detach_port_num_from_logical_switch(unsigned int port_num, of_switch_t *sw)
Detaches port located at port_num from logical switch sw.
Port abstraction.
Definition: switch_port.h:145
switch_port_t ** physical_switch_get_tunnel_ports(unsigned int *max_ports)
Get the reference to the physical ports.
switch_port_t * physical_switch_get_port_by_name(const char *name)
Retrieve a physical switch port by name.
List of dpids (snapshots)
switch_port_snapshot_t * physical_switch_get_port_snapshot(const char *name)
Gets a snapshot of the current port state, if it exists.
rofl_result_t physical_switch_detach_port_from_logical_switch(switch_port_t *port, of_switch_t *sw)
Detaches port from logical switch sw.
switch_port_t ** physical_switch_get_physical_ports(unsigned int *max_ports)
Get the reference to the physical ports.
physical_switch_t * get_physical_switch(void)
Get the reference to the (unique) physical switch.
Keeps the state of the physical switch (device), including ports and logical switch instances...
struct physical_switch physical_switch_t
Keeps the state of the physical switch (device), including ports and logical switch instances...
of_switch_t * physical_switch_get_logical_switch_by_dpid(const uint64_t dpid)
Attemps to retrieve a logical switch from the pool by its dpid.
rofl_result_t physical_switch_add_port(switch_port_t *port)
Adds a port to the physical_switch pool portAttempts to add a port to the physical switch pool port...
switch_port_t * physical_switch_get_port_by_num(const uint64_t dpid, unsigned int port_num)
Retrieve a port attached to logical switch with dpid at port num.
OpenFlow logical switch meta-abstraction.
void physical_switch_destroy(void)
Destroys the physical switch state.
#define PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS
Maximum number of tunnel ports.
dpid_list_t * physical_switch_get_all_lsi_dpids(void)
Get the list of existing LSI DPIDs.
of_switch_t * physical_switch_get_logical_switch_attached_to_port(const switch_port_t port)
Attemps to retrieve the logical switch attached to the port.
switch_port_t * in_port_meta_port
Special meta port: IN_PORT.
switch_port_name_list_t * physical_switch_get_all_port_names(void)
Gets a list of port names of all (currently) available port names.
rofl_result_t physical_switch_remove_logical_switch_by_dpid(const uint64_t dpid)
Attemps to remove AND destroy a previously added logical switch from the pool by dpid.
switch_port_t * flood_meta_port
Special meta port: FLOOD.
This file contains the abstractions to monitor particular elements of the platform, like sensors or other hardware state.
static monitoring_state_t * physical_switch_get_monitoring(void)
Retrieves the monitoring state of the physicals witch.