3 #include "../../switch_port.h"
4 #include "../../platform/lock.h"
5 #include "../../platform/memory.h"
6 #include "../../platform/likely.h"
7 #include "../../util/logging.h"
8 #include "../of_switch.h"
12 of1x_switch_t*
of1x_init_switch(
const char* name, of_version_t version, uint64_t dpid,
unsigned int num_of_tables,
enum of1x_matching_algorithm_available* list){
16 if( unlikely(sw == NULL) )
22 strncpy(sw->name,name,LOGICAL_SWITCH_MAX_LEN_NAME);
27 sw->max_ports=LOGICAL_SWITCH_MAX_LOG_PORTS;
30 sw->platform_state=NULL;
39 if(__of1x_init_pipeline(sw, num_of_tables, list) != ROFL_SUCCESS){
46 __of1x_destroy_pipeline(&sw->pipeline);
62 result = __of1x_destroy_pipeline(&sw->pipeline);
76 rofl_result_t __of1x_reconfigure_switch(
of1x_switch_t* sw, of_version_t version){
78 if(sw->of_ver == version)
81 if(version == OF_VERSION_11)
85 if(__of1x_purge_pipeline_entries(&sw->pipeline) != ROFL_SUCCESS)
89 if(__of1x_set_pipeline_tables_defaults(&sw->pipeline, version) != ROFL_SUCCESS)
100 if( unlikely(port==NULL) || unlikely(port_num==0) || unlikely(port_num >= LOGICAL_SWITCH_MAX_LOG_PORTS) )
106 if(sw->logical_ports[port_num].attachment_state != LOGICAL_PORT_STATE_FREE){
112 sw->logical_ports[port_num].attachment_state = LOGICAL_PORT_STATE_ATTACHED;
113 sw->logical_ports[port_num].port = port;
118 port->of_port_num = port_num;
128 if( unlikely(port==NULL) || unlikely(port->attached_sw!=NULL) )
134 for(i=1;i<LOGICAL_SWITCH_MAX_LOG_PORTS;i++){
135 if(!sw->logical_ports[i].attachment_state){
137 sw->logical_ports[i].attachment_state = LOGICAL_PORT_STATE_ATTACHED;
138 sw->logical_ports[i].port = port;
144 port->of_port_num = i;
157 rofl_result_t __of1x_detach_port_from_switch_by_port_num(
of1x_switch_t* sw,
unsigned int port_num){
159 if( unlikely(port_num==0) )
165 if(sw->logical_ports[port_num].attachment_state != LOGICAL_PORT_STATE_ATTACHED){
171 sw->logical_ports[port_num].port->attached_sw = NULL;
172 sw->logical_ports[port_num].port->of_port_num = 0;
176 sw->logical_ports[port_num].attachment_state = LOGICAL_PORT_STATE_FREE;
177 sw->logical_ports[port_num].port = NULL;
189 if( unlikely(port==NULL) )
195 for(i=0;i<LOGICAL_SWITCH_MAX_LOG_PORTS;i++){
196 if(sw->logical_ports[i].port == port){
199 sw->logical_ports[i].port->attached_sw = NULL;
200 sw->logical_ports[i].port->of_port_num = 0;
205 sw->logical_ports[i].attachment_state = LOGICAL_PORT_STATE_FREE;
206 sw->logical_ports[i].port = NULL;
219 rofl_result_t __of1x_detach_all_ports_from_switch(
of1x_switch_t* sw){
226 for(i=0;i<LOGICAL_SWITCH_MAX_LOG_PORTS;i++){
229 if(sw->logical_ports[i].port)
230 sw->logical_ports[i].port->attached_sw = NULL;
235 sw->logical_ports[i].attachment_state = LOGICAL_PORT_STATE_FREE;
236 sw->logical_ports[i].port = NULL;
247 ROFL_PIPELINE_INFO(
"\n");
248 ROFL_PIPELINE_INFO(
"OpenFlow switch instance (%p)\n",sw);
249 ROFL_PIPELINE_INFO(
"========================\n");
250 ROFL_PIPELINE_INFO(
"Name: %s\n",sw->name);
251 ROFL_PIPELINE_INFO(
"OpenFlow version: %s\n", of_version_str[sw->of_ver]);
252 ROFL_PIPELINE_INFO(
"OpenFlow datapathid: 0x%" PRIx64
"\n",sw->dpid);
260 for(i=0;i<sw->pipeline.num_of_tables;i++)
261 of1x_dump_table(&sw->pipeline.tables[i], nbo);
262 ROFL_PIPELINE_INFO(
"--End of pipeline tables--\n");
264 of1x_dump_group_table(sw->pipeline.groups, nbo);
265 ROFL_PIPELINE_INFO(
"--End of group table--\n\n");
290 sn->mutex = sn->platform_state = NULL;
293 for(i=0;i<LOGICAL_SWITCH_MAX_LOG_PORTS;i++){
294 if(sw->logical_ports[i].port){
296 sn->logical_ports[i].port = __switch_port_get_snapshot(sw->logical_ports[i].port);
297 if(!sn->logical_ports[i].port)
298 goto ports_only_snapshoting_error;
303 if(__of1x_pipeline_get_snapshot(&sw->pipeline, &sn->pipeline) != ROFL_SUCCESS)
304 goto pipeline_snapshoting_error;
310 pipeline_snapshoting_error:
313 ports_only_snapshoting_error:
316 if(sn->logical_ports[i].port)
334 __of1x_pipeline_destroy_snapshot(&sn->pipeline);
337 for(i=0;i<LOGICAL_SWITCH_MAX_LOG_PORTS;i++){
338 if(sn->logical_ports[i].port)
OpenFlow-enabled switch abstraction (version-indepedent part).
OpenFlow-enabled v1.0, 1.2 and 1.3.2 switch abstraction.
rofl_result_t platform_pre_destroy_of1x_switch(of1x_switch_t *sw)
Allows the user of the library to perform other platform related actions when a switch is about the b...
void switch_port_destroy_snapshot(switch_port_snapshot_t *port)
Destroy a switch port snapshot.
ROFL_BEGIN_DECLS rofl_result_t platform_post_init_of1x_switch(of1x_switch_t *sw)
Allows the user of the library to pre-configure the switch, as well as perform other platform related...
of1x_switch_t * of1x_init_switch(const char *name, of_version_t version, uint64_t dpid, unsigned int num_of_tables, enum of1x_matching_algorithm_available *list)
Creates an OpenFlow v1.0, 1.2 and 1.3.2 forwarding instance.
OpenFlow v1.0, 1.2 and 1.3.2 switch(fwd module) -> asynchronous event notification and hooks) ...
void of1x_dump_switch(of1x_switch_t *sw, bool nbo)
Dumps the OpenFlow v1.0, 1.2 and 1.3.2 forwarding instance, for debugging purposes.
OpenFlow v1.0, 1.2 and 1.3.2 logical switch abstraction.
void of1x_full_dump_switch(of1x_switch_t *sw, bool nbo)
Dumps the OpenFlow v1.0, 1.2 and 1.3.2 forwarding instance, for debugging purposes.