ROFL-pipeline  v0.6.0dev
switch_port.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 
13 #ifndef __PHYSICAL_PORT_H__
14 #define __PHYSICAL_PORT_H__
15 
16 #include <stdbool.h>
17 #include <inttypes.h>
18 
19 #include "rofl.h"
20 #include "port_queue.h"
21 #include "common/bitmap.h"
22 #include "platform/lock.h"
23 
24 
25 //fwd decl
26 struct of_switch;
27 
28 #define SW_PORT_ETH_ALEN 6
29 #define SWITCH_PORT_MAX_LEN_NAME 32
30 #define SWITCH_PORT_MAX_QUEUES 16
31 
36 typedef enum{
37  PORT_STATE_NONE = 0 << 0,
38  PORT_STATE_LINK_DOWN = 1 << 0,
39  PORT_STATE_BLOCKED = 1 << 1, //We are not hybrid we might not need this
40  PORT_STATE_LIVE = 1 << 2,
42 
47 typedef enum port_features{
48  PORT_FEATURE_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
49  PORT_FEATURE_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
50  PORT_FEATURE_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
51  PORT_FEATURE_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
52  PORT_FEATURE_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
53  PORT_FEATURE_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
54  PORT_FEATURE_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
55  PORT_FEATURE_40GB_FD = 1 << 7, /* 40 Gb full-duplex rate support. */
56  PORT_FEATURE_100GB_FD = 1 << 8, /* 100 Gb full-duplex rate support. */
57  PORT_FEATURE_1TB_FD = 1 << 9, /* 1 Tb full-duplex rate support. */
58  PORT_FEATURE_OTHER = 1 << 10, /* Other rate, not in the list. */
59 
60  PORT_FEATURE_COPPER = 1 << 11, /* Copper medium. */
61  PORT_FEATURE_FIBER = 1 << 12, /* Fiber medium. */
62  PORT_FEATURE_AUTONEG = 1 << 13, /* Auto-negotiation. */
63  PORT_FEATURE_PAUSE = 1 << 14, /* Pause. */
64  PORT_FEATURE_PAUSE_ASYM = 1 << 15 /* Asymmetric pause. */
66 
67 //Opaque platform port state (to be used, maybe, for platform hooks)
68 typedef void platform_port_state_t;
69 
74 typedef struct port_stats {
75  uint64_t rx_packets; /* Number of received packets. */
76  uint64_t tx_packets; /* Number of transmitted packets. */
77  uint64_t rx_bytes; /* Number of received bytes. */
78  uint64_t tx_bytes; /* Number of transmitted bytes. */
79  uint64_t rx_dropped; /* Number of packets dropped by RX. */
80  uint64_t tx_dropped; /* Number of packets dropped by TX. */
81  uint64_t rx_errors; /* Number of receive errors. This is a super-set
82  of more specific receive errors and should be
83  greater than or equal to the sum of all
84  rx_*_err values. */
85  uint64_t tx_errors; /* Number of transmit errors. This is a super-set
86  of more specific transmit errors and should be
87  greater than or equal to the sum of all
88  tx_*_err values (none currently defined.) */
89  uint64_t rx_frame_err; /* Number of frame alignment errors. */
90  uint64_t rx_over_err; /* Number of packets with RX overrun. */
91  uint64_t rx_crc_err; /* Number of CRC errors. */
92  uint64_t collisions; /* Number of collisions. */
93 
94  //Mutex for statistics
95  platform_mutex_t* mutex;
97 
106 typedef enum port_type{
107  PORT_TYPE_INVALID = 0,
108  PORT_TYPE_PHYSICAL = 1,
109  PORT_TYPE_VIRTUAL = 2,
110  PORT_TYPE_TUNNEL = 3,
111 
112  //Special META(fake) ports
113  //PORT_TYPE_META = 4,
114  PORT_TYPE_META_FLOOD = 5,
115  PORT_TYPE_META_IN_PORT = 6,
116  PORT_TYPE_META_ALL = 7,
117 
118  /*
119  * Other types of port
120  */
121 
122  //Network Functions port types
123  //NFs are exported to the OF pipeline
124  //as ports
125  PORT_TYPE_NF_NATIVE = 8, //Native
126  PORT_TYPE_NF_SHMEM = 9, //External NF but with shared memory
127  PORT_TYPE_NF_EXTERNAL = 10 //External NF (e.g. real port)
128 }port_type_t;
129 
130 
145 typedef struct switch_port{
146 
147  //mac address
148  uint8_t hwaddr[SW_PORT_ETH_ALEN];
149 
150  /* General state */
151  //Admin. state of the port
152  bool up;
153 
154  //Forward packets
155  bool forward_packets;
156 
157  //Drop incomming packets
158  bool drop_received;
159 
160  //don't forward flood packets (OF1.0 only)
161  bool no_flood;
162 
163  //Is virtual/tun
164  port_type_t type;
165 
166  //Port name
167  char name[SWITCH_PORT_MAX_LEN_NAME];
168 
169  //Port state (port_state_t bitmap)
170  bitmap32_t state;
171 
172  // Port statistics
173  port_stats_t stats;
174 
175  //Port capabilities; port_features_t bitmaps!
176  bitmap32_t curr; /* Current features. */
177  bitmap32_t advertised; /* Features being advertised by the port. */
178  bitmap32_t supported; /* Features supported by the port. */
179  bitmap32_t peer; /* Features advertised by peer. */
180 
181  //Current speeds
182  port_features_t curr_speed;
183  port_features_t curr_max_speed;
184 
185  //Queues
186  unsigned int max_queues; //This must be <= SWITCH_PORT_MAX_QUEUES
187  port_queue_t queues[SWITCH_PORT_MAX_QUEUES];
188 
189  /*
190  * OF related stuff
191  */
192  bool of_generate_packet_in;
193 
194  //Pointer to current logical switch attached
195  struct of_switch* attached_sw;
196 
197  /*
198  * Only used in snapshots
199  */
200  bool is_attached_to_sw;
201  uint64_t attached_sw_dpid;
202  //OF port number != physical port num
203  unsigned int of_port_num;
204 
205  //Mutex for statistics
206  platform_mutex_t* mutex;
207 
208  /* Opaque platform port specific extra state */
209  platform_port_state_t* platform_port_state;
211 
212 /* Logical port abstraction (to be used by logical switches) */
213 typedef enum logical_switch_port_attachment_state{
214  LOGICAL_PORT_STATE_FREE = 0,
215  LOGICAL_PORT_STATE_ATTACHED = 1,
216  LOGICAL_PORT_STATE_DETACHED = 2
217 }logical_switch_port_attachment_state_t;
218 
219 typedef struct logical_switch_port{
220  logical_switch_port_attachment_state_t attachment_state;
221  switch_port_t* port;
223 
224 
232 typedef struct __switch_port_name{
233  char name[SWITCH_PORT_MAX_LEN_NAME];
235 
236 typedef struct switch_port_name_list{
237 
238  //Number of ports in the port list
239  unsigned int num_of_ports;
240 
241  //Names
242  __switch_port_name_t* names;
244 
245 /*
246 * Functions
247 */
248 
249 
250 
251 
252 //C++ extern C
253 ROFL_BEGIN_DECLS
254 
259 switch_port_t* switch_port_init(char* name, bool up, port_type_t type, port_state_t state);
260 
265 rofl_result_t switch_port_destroy(switch_port_t* port);
266 
271 rofl_result_t switch_port_add_queue(switch_port_t* port, uint32_t id, char* name, uint16_t length, uint16_t min_rate, uint16_t max_rate);
272 
277 rofl_result_t switch_port_remove_queue(switch_port_t* port, uint32_t id);
278 
279 //Port Statistics
280 
281 /*
282 * Conveninent wrappers just to avoid messing up with the bitmaps
283 */
284 
289 void switch_port_add_capabilities(bitmap32_t* bitmap, bitmap32_t features);
290 
295 void switch_port_remove_capabilities(bitmap32_t* bitmap, bitmap32_t features);
296 
302 
308 
309 //
310 // Snapshots
311 //
312 
313 //Internal call for port snapshoting
314 switch_port_snapshot_t* __switch_port_get_snapshot(switch_port_t* port);
315 
321 
327 
333 
334 //C++ extern C
335 ROFL_END_DECLS
336 
337 #endif //PHYSICAL_PORT
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...
enum port_features port_features_t
Port features.
port_features
Port features.
Definition: switch_port.h:47
void switch_port_destroy_snapshot(switch_port_snapshot_t *snapshot)
Destroy a switch port snapshot.
Definition: switch_port.c:195
void switch_port_name_list_destroy(switch_port_name_list_t *list)
Destroys a port name list, previously generated by calling fwd_module_get_all_port_names() ...
Definition: switch_port.c:201
void switch_port_set_current_speed(switch_port_t *port, port_features_t speed)
Sets current speed.
Definition: switch_port.c:139
port_state_t
Port state.
Definition: switch_port.h:36
switch_port_snapshot_t * switch_port_clone_snapshot(switch_port_snapshot_t *orig)
Clone a snapshot.
Definition: switch_port.c:183
List of ports name (snapshots)
Definition: switch_port.h:232
struct port_stats port_stats_t
Port stats.
switch_port_t switch_port_snapshot_t
Snapshot of the port.
Definition: switch_port.h:228
void switch_port_add_capabilities(bitmap32_t *bitmap, bitmap32_t features)
Adds capabilities to the port.
Definition: switch_port.c:133
enum port_type port_type_t
Port type enumeration.
struct __switch_port_name __switch_port_name_t
List of ports name (snapshots)
ROFL_BEGIN_DECLS switch_port_t * switch_port_init(char *name, bool up, port_type_t type, port_state_t state)
Init a switch_port structure.
Definition: switch_port.c:11
rofl_result_t switch_port_remove_queue(switch_port_t *port, uint32_t id)
Remove queue from port.
Definition: switch_port.c:113
struct switch_port switch_port_t
Port abstraction.
Port abstraction.
Definition: switch_port.h:145
Port stats.
Definition: switch_port.h:74
port_type
Port type enumeration.
Definition: switch_port.h:106
rofl_result_t switch_port_destroy(switch_port_t *port)
Destroy a switch_port structure.
Definition: switch_port.c:66
Defines common bitmap operations, specially for large types.
rofl_result_t switch_port_add_queue(switch_port_t *port, uint32_t id, char *name, uint16_t length, uint16_t min_rate, uint16_t max_rate)
Add queue to port.
Definition: switch_port.c:92
void switch_port_set_current_max_speed(switch_port_t *port, port_features_t speed)
Sets current MAX speed.
Definition: switch_port.c:144
void switch_port_remove_capabilities(bitmap32_t *bitmap, bitmap32_t features)
Removes capabilities to the port.
Definition: switch_port.c:136
Switch queue abstraction.
Definition: port_queue.h:49
Port queue abstraction.