-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch13.h
More file actions
191 lines (146 loc) · 6.89 KB
/
switch13.h
File metadata and controls
191 lines (146 loc) · 6.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#ifndef _SWITCH13_H_
#define _SWITCH13_H_
#include <string>
#include <cstdlib>
#include "netinet++/datapathid.hh"
#include "nox.hh"
#include "openflow-default.hh"
#include "flow.hh"
#include "ofp-msg-event.hh"
#include "flowmod.hh"
#include "datapath-join.hh"
#include "../../../oflib/ofl-actions.h"
#include "../../../oflib/ofl-messages.h"
namespace pfswitch13{
enum of_tmod_cmd{OFTM_ADD,OFTM_MODIFY,OFTM_DELETE};
typedef uint32_t ipv4_addr;
struct SwitchData{
public:
unsigned pid; ///< The paths identifier.
std::string as; ///< The path's identifier is treaten as... (VLAN ID, etc.)
unsigned in_port; ///< In port of the packets.
unsigned out_port; ///< Out port of the packets.
public:
/// Ctor;
SwitchData(unsigned pid,const std::string &as,
unsigned in_port,unsigned out_port):pid(pid),as(as),in_port(in_port),out_port(out_port){}
};
/// \class Switch13
/// Base class for all the switch types used in path-flow model.
class Switch13{
protected:
vigil::datapathid dpid; ///< The dpid of the switch.
std::string name; ///< The human readable name of the switch.
SwitchData data; ///< The base config data of the switch.
unsigned tnum; ///< Tablenum.
vigil::Flow self; ///< The flows matching this switch.
void *uid; ///< User defined stuff.
public:
/// CTor.
Switch13(const vigil::datapathid dpid,const std::string &name,
const SwitchData &data):dpid(dpid),name(name),data(data),tnum(0),uid(0){}
/// CTor.
Switch13(const unsigned dpid,const std::string &name,
const SwitchData &data):dpid(vigil::datapathid::from_host(dpid)),name(name),data(data),tnum(0),uid(0){}
/// CTor.
Switch13(const uint64_t dpid,const std::string &name,
const SwitchData &data):dpid(vigil::datapathid::from_host(dpid)),name(name),data(data),tnum(0),uid(0){}
/// Virtual dTor, due to the virtual stuff.
virtual ~Switch13(){
free(uid);
}
/// Init the switch. This method will generate the match structure for the switch.
virtual void init(){
self.Add_Field("in_port",data.in_port); // in_port
self.Add_Field(data.as.c_str(),data.pid); // vlan_vid
}
/// Attach an user defined piece of data to the switch.
Switch13& attach(const void *_uid,size_t size){
free(uid);
uid=malloc(size);
memcpy(uid,_uid,size);
return *this;
}
/// Retrun true, if the datapath id of the switch is equal
/// to the given datapath id.
bool operator==(const vigil::datapathid _dpid)const{
return dpid==_dpid;
}
/// Get the DPID of the switch. On the same dpid there are sitting
/// multiple switches acting differenty/having different roles.
vigil::datapathid getDPID()const{
return dpid;
}
/// Get the user defined name of the switch.
std::string getName()const{
return name;
}
/// This method returns the user defined piece of data stored
/// along with the switch.
void* getUID()const{
return uid;
}
/// Returns true if the match structure of the switch is
/// the same as the given match structure.
/// \todo string formats are compared; find a better way!
bool same(struct ofl_match *match)const{
return (self.to_string()==vigil::Flow(match).to_string());
}
virtual bool responsible(unsigned pid)const{
return data.pid==pid;
}
/// Configrure the switch (i.e., its rule) on the physical switch.
virtual void configure(unsigned=0,enum of_tmod_cmd=OFTM_ADD)=0;
/// Change bucket weights.
virtual void switchWeights(unsigned*,enum of_tmod_cmd=OFTM_MODIFY)=0;
/// Send stat request message.
virtual void statReq()const{
/*
struct ofl_msg_header {
enum ofp_type type; // One of the OFPT_ constants.
};
struct ofl_msg_multipart_request_header {
struct ofl_msg_header header; // OFPT_MULTIPART_REQUEST
enum ofp_multipart_types type; // One of the OFPMP_* constants.
uint16_t flags; // OFPSF_REQ_* flags (none yet defined).
};
struct ofl_msg_multipart_request_flow{
struct ofl_msg_multipart_request_header header; // OFPMP_FLOW/AGGREGATE
uint8_t table_id; // ID of table to read
uint32_t out_port; // Require matching entries to include this as an output port. OFPP_ANY
uint32_t out_group; // Require matching entries to include this as an output group. OFPG_ANY
uint64_t cookie; // Require matching entries to contain this cookie value
uint64_t cookie_mask; // Mask used to restrict the cookie bits that must match. A value of 0 indicates no restriction.
struct ofl_match_header *match; // Fields to match.
};
struct ofl_match_header {
uint16_t type; // One of OFPMT_*
uint16_t length; // Match length
};
*/
}
static ofp_flow_mod_command toFlowCmd(enum of_tmod_cmd cmd){
switch(cmd){
case OFTM_ADD:
return OFPFC_ADD;
case OFTM_MODIFY:
return OFPFC_MODIFY;
default:
return OFPFC_DELETE;
}
return OFPFC_ADD;
}
static ofp_group_mod_command toGroupCmd(enum of_tmod_cmd cmd){
switch(cmd){
case OFTM_ADD:
return OFPGC_ADD;
case OFTM_MODIFY:
return OFPGC_MODIFY;
default:
return OFPGC_DELETE;
}
return OFPGC_ADD;
}
}; // class Switch13
}; // namespace pfswitch13
#endif // _SWITCH13_H_