6 #include "platform/likely.h"
7 #include "util/logging.h"
9 #include "openflow/openflow1x/pipeline/matching_algorithms/matching_algorithms.h"
14 #define META_PORT_FLOOD_INDEX 0
15 #define META_PORT_IN_PORT_INDEX 1
16 #define META_PORT_ALL_INDEX 2
28 void __physical_switch_generate_matching_algorithm_list(){
29 __of1x_generate_matching_algorithm_list();
36 ROFL_PIPELINE_DEBUG(
"Initializing physical switch\n");
41 if( unlikely(psw==NULL) )
48 platform_memset(psw->logical_switches, 0,
sizeof(psw->logical_switches));
49 psw->num_of_logical_switches = 0;
58 psw->meta_ports[META_PORT_FLOOD_INDEX].type = PORT_TYPE_META_FLOOD;
59 strncpy(psw->meta_ports[META_PORT_FLOOD_INDEX].name,
"Flood meta port", SWITCH_PORT_MAX_LEN_NAME);
61 psw->meta_ports[META_PORT_IN_PORT_INDEX].type = PORT_TYPE_META_IN_PORT;
62 strncpy(psw->meta_ports[META_PORT_IN_PORT_INDEX].name,
"In port meta port", SWITCH_PORT_MAX_LEN_NAME);
64 psw->meta_ports[META_PORT_ALL_INDEX].type = PORT_TYPE_META_ALL;
65 strncpy(psw->meta_ports[META_PORT_ALL_INDEX].name,
"All meta port", SWITCH_PORT_MAX_LEN_NAME);
68 flood_meta_port = &psw->meta_ports[META_PORT_FLOOD_INDEX];
69 in_port_meta_port = &psw->meta_ports[META_PORT_IN_PORT_INDEX];
70 all_meta_port = &psw->meta_ports[META_PORT_ALL_INDEX];
77 __physical_switch_generate_matching_algorithm_list();
91 flood_meta_port = &psw->meta_ports[META_PORT_FLOOD_INDEX];
92 in_port_meta_port = &psw->meta_ports[META_PORT_IN_PORT_INDEX];
93 all_meta_port = &psw->meta_ports[META_PORT_ALL_INDEX];
101 ROFL_PIPELINE_DEBUG(
"Destroying physical switch\n");
108 if(psw->logical_switches[i])
114 if( psw->physical_ports[i] != NULL ){
119 if( psw->virtual_ports[i] != NULL ){
124 if( psw->tunnel_ports[i] != NULL ){
130 __monitoring_destroy(&psw->monitoring);
150 if( psw->physical_ports[i] != NULL && strncmp(psw->physical_ports[i]->name, name, SWITCH_PORT_MAX_LEN_NAME)==0 ){
151 return psw->physical_ports[i];
157 if( psw->virtual_ports[i] != NULL && strncmp(psw->virtual_ports[i]->name, name, SWITCH_PORT_MAX_LEN_NAME)==0 ){
158 return psw->virtual_ports[i];
164 if( psw->tunnel_ports[i] != NULL && strncmp(psw->tunnel_ports[i]->name, name, SWITCH_PORT_MAX_LEN_NAME)==0 ){
165 return psw->tunnel_ports[i];
176 return psw->physical_ports;
181 return psw->virtual_ports;
186 return psw->tunnel_ports;
198 if( unlikely(lsw==NULL) )
202 if( port_num >= LOGICAL_SWITCH_MAX_LOG_PORTS || port_num == 0)
205 if( lsw->logical_ports[port_num].attachment_state != LOGICAL_PORT_STATE_ATTACHED )
208 return lsw->logical_ports[port_num].port;
220 if( unlikely(port==NULL) )
223 ROFL_PIPELINE_DEBUG(
"Trying to add port(%p) named %s to the physical switch\n", port, port->name);
226 ROFL_PIPELINE_DEBUG(
"There is already a port named:%s in the physical switch\n",port->name);
235 case PORT_TYPE_PHYSICAL:
237 array = psw->physical_ports;
240 case PORT_TYPE_VIRTUAL:
242 array = psw->virtual_ports;
245 case PORT_TYPE_TUNNEL:
247 array = psw->tunnel_ports;
250 case PORT_TYPE_NF_NATIVE:
251 case PORT_TYPE_NF_SHMEM:
252 case PORT_TYPE_NF_EXTERNAL:
255 array = psw->physical_ports;
266 if(array[i] == NULL){
276 ROFL_PIPELINE_DEBUG(
"Insertion failed of port(%p); no available slots\n",port);
288 if( unlikely(name==NULL) )
297 if( psw->physical_ports[i] != NULL && strncmp(psw->physical_ports[i]->name, name, SWITCH_PORT_MAX_LEN_NAME) == 0 ){
298 port = psw->physical_ports[i];
299 psw->physical_ports[i] = NULL;
308 if( psw->virtual_ports[i] != NULL && strncmp(psw->virtual_ports[i]->name, name, SWITCH_PORT_MAX_LEN_NAME) == 0 ){
309 port = psw->virtual_ports[i];
310 psw->virtual_ports[i] = NULL;
319 if( psw->tunnel_ports[i] != NULL && strncmp(psw->tunnel_ports[i]->name, name, SWITCH_PORT_MAX_LEN_NAME) == 0 ){
320 port = psw->tunnel_ports[i];
321 psw->tunnel_ports[i] = NULL;
349 return psw->logical_switches;
358 if( psw->logical_switches[i] && psw->logical_switches[i]->dpid == dpid )
359 return psw->logical_switches[i];
384 if(!psw->logical_switches[i])
388 psw->logical_switches[i] = sw;
389 psw->num_of_logical_switches++;
400 ROFL_PIPELINE_DEBUG(
"Removing logical switch with dpid: 0x%"PRIx64
"\n",dpid);
407 ROFL_PIPELINE_WARN(
"Logical switch not found\n");
412 if(psw->logical_switches[i] && psw->logical_switches[i]->dpid == dpid){
414 sw = psw->logical_switches[i];
416 psw->logical_switches[i] = NULL;
417 psw->num_of_logical_switches--;
451 rofl_result_t return_val;
453 if( unlikely(sw==NULL) || unlikely(port==NULL) || unlikely(port->attached_sw!=NULL) )
459 return_val = __of_attach_port_to_switch(sw, port, port_num);
468 rofl_result_t return_val;
470 if( unlikely(sw==NULL) || unlikely(port==NULL) || unlikely(port->attached_sw!=NULL) )
476 return_val = __of_attach_port_to_switch_at_port_num(sw, port_num, port);
484 rofl_result_t return_val;
486 if( unlikely(sw==NULL) )
492 return_val = __of_detach_port_from_switch_by_port_num(sw, port_num);
501 rofl_result_t return_val;
503 if( unlikely(sw==NULL) || unlikely(port==NULL) )
509 return_val = __of_detach_port_from_switch(sw, port);
519 rofl_result_t return_val;
521 if( unlikely(sw==NULL) )
527 return_val = __of_detach_all_ports_from_switch(sw);
544 unsigned int num_of_ports, i;
552 if(psw->physical_ports[i])
556 if(psw->tunnel_ports[i])
560 if(psw->virtual_ports[i])
579 list->num_of_ports = num_of_ports;
583 if(psw->physical_ports[i]){
584 memcpy(&list->names[num_of_ports], &psw->physical_ports[i]->name, SWITCH_PORT_MAX_LEN_NAME);
589 if(psw->tunnel_ports[i]){
590 memcpy(&list->names[num_of_ports], &psw->tunnel_ports[i]->name, SWITCH_PORT_MAX_LEN_NAME);
595 if(psw->virtual_ports[i]){
596 memcpy(&list->names[num_of_ports], &psw->virtual_ports[i]->name, SWITCH_PORT_MAX_LEN_NAME);
625 snapshot = __switch_port_get_snapshot(port);
644 list->num_of_lsis = psw->num_of_logical_switches;
657 if(psw->logical_switches[i]){
658 list->dpids[j] = psw->logical_switches[i]->dpid;
686 to_return = __of_switch_get_snapshot(sw);
#define PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS
Maximum number of virtual ports.
OpenFlow-enabled switch abstraction (version-indepedent part).
Defines the locking interface used by the library. The user of the library MUST provide an implementa...
Defines the memory management interface used by the library. The user of the library MUST provide an ...
rofl_result_t physical_switch_add_logical_switch(of_switch_t *sw)
Add a logical switch to the pool.
rofl_result_t physical_switch_init()
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.
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...
List of ports name (snapshots)
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.
void dpid_list_destroy(dpid_list_t *list)
Destroy a previously generated list of dpids.
Physical switch abstraction and API.
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.
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)
rofl_result_t switch_port_destroy(switch_port_t *port)
Destroy a switch_port structure.
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()
Get the reference to the (unique) physical switch.
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.
rofl_result_t of_destroy_switch(const of_switch_t *sw)
Destroys an OpenFlow logical switch.
void physical_switch_destroy()
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.
ROFL_BEGIN_DECLS rofl_result_t __monitoring_init(monitoring_state_t *monitoring)
Initializes the monitoring state.
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.