-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitchs4.h
More file actions
184 lines (139 loc) · 6.09 KB
/
switchs4.h
File metadata and controls
184 lines (139 loc) · 6.09 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
#ifndef _SWITCHS4_H_
#define _SWITCHS4_H_
#include <string>
//#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"
#include "switch13.h"
#include "groupmod.h"
namespace pfswitch13{
using namespace vigil;
/// PathHdr - null teminated, i.e., the last elements pid have to be zero!
struct PathHdr{
public:
unsigned pid;
unsigned out_port;
public:
PathHdr():pid(0),out_port(0){}
PathHdr(unsigned pid,unsigned out_port):pid(pid),out_port(out_port){}
};
class SwitchS4:public SwitchS1{
protected:
PathHdr *ps; ///< Path header is moved!
public:
SwitchS4(const vigil::datapathid dpid,const std::string &name,
ipv4_addr src_ip,ipv4_addr dst_ip,
const SwitchData &data,
PathHdr **_ps):SwitchS1(dpid,name,src_ip,dst_ip,data){
ps=*_ps;
*_ps=0;
}
SwitchS4(const unsigned dpid,const std::string &name,
ipv4_addr src_ip,ipv4_addr dst_ip,
const SwitchData &data,
PathHdr **_ps):SwitchS1(dpid,name,src_ip,dst_ip,data){
ps=*_ps;
*_ps=0;
}
SwitchS4(const uint64_t dpid,const std::string &name,
ipv4_addr src_ip,ipv4_addr dst_ip,
const SwitchData &data,
PathHdr **_ps):SwitchS1(dpid,name,src_ip,dst_ip,data){
ps=*_ps;
*_ps=0;
}
virtual ~SwitchS4(){
delete ps;
}
virtual bool responsible(unsigned pid)const{
PathHdr *p=ps; // temp pointer to be used and aletered
while(p->pid){
if(p->pid==pid) return true;
p++;
}
return false;
}
virtual void configure(unsigned _tnum=0,enum of_tmod_cmd cmd=OFTM_ADD){
tnum=_tnum;
if(!ps || ps->pid==0) return;
// multiple flows - group table
GroupMod *gmod=new GroupMod(data.pid,toGroupCmd(cmd) /*OFPGC_ADD*/,OFPGT_SELECT); //ADD, MODIFY, DELETE
std::vector<Actions*> gr_acts;
PathHdr *p=ps;
while(p->pid){
Actions *acts1=new Actions();
gr_acts.push_back(acts1);
if(data.as=="vlan_id"){
// VLAN
acts1->CreatePushAction(OFPAT_PUSH_VLAN,0x8100);
acts1->CreateSetField("vlan_id",&(p->pid));
acts1->CreateOutput(p->out_port);
}
else{
// MPLS
acts1->CreatePushAction(OFPAT_PUSH_MPLS,0x8100);
acts1->CreateSetField("mpls_label",&(p->pid));
acts1->CreateOutput(p->out_port);
}
// all buckets have equal weights - startup;
// call switchWeights to alter weights
gmod->addBucket(1,0,0,acts1);
p++;
}
nox::send_openflow_msg(dpid,(struct ofl_msg_header *)&gmod->gr_msg,0,true);
// delete actions
for(std::vector<Actions*>::iterator it=gr_acts.begin();it!=gr_acts.end();++it){
delete *it;
}
//std::cerr<<self.to_string()<<"\n";
Actions *acts=new Actions();
acts->CreateGroupAction(data.pid);
Instruction *inst=new Instruction();
inst->CreateApply(acts);
FlowMod *mod = new FlowMod(0x00ULL,0x00ULL,tnum,
toFlowCmd(cmd), //OFPFC_ADD, // cf
OFP_FLOW_PERMANENT,
OFP_FLOW_PERMANENT,
OFP_DEFAULT_PRIORITY, // tnum
0,
OFPP_ANY,OFPG_ANY,ofd_flow_mod_flags());
mod->AddMatch(&self.match);
mod->AddInstructions(inst);
nox::send_openflow_msg(dpid,(struct ofl_msg_header *)&mod->fm_msg,0,true);
//delete inst; delete acts;
}
virtual void switchWeights(unsigned *ratios,enum of_tmod_cmd cmd=OFTM_MODIFY){
GroupMod *gmod=new GroupMod(data.pid,toGroupCmd(cmd) /*OFPGC_MODIFY*/,OFPGT_SELECT); //ADD, MODIFY, DELETE
std::vector<Actions*> gr_acts; // to store actions
PathHdr *p=ps; // temp pointer to be used and aletered
while(p->pid){
Actions *acts1=new Actions();
gr_acts.push_back(acts1);
if(data.as=="vlan_id"){
// VLAN
acts1->CreatePushAction(OFPAT_PUSH_VLAN,0x8100);
acts1->CreateSetField("vlan_id",&(p->pid));
acts1->CreateOutput(p->out_port);
}
else{
// MPLS
acts1->CreatePushAction(OFPAT_PUSH_MPLS,0x8100);
acts1->CreateSetField("mpls_label",&(p->pid));
acts1->CreateOutput(p->out_port);
}
gmod->addBucket(*ratios++,0,0,acts1);
p++;
}
nox::send_openflow_msg(dpid,(struct ofl_msg_header *)&gmod->gr_msg,0,true);
// delete actions
for(std::vector<Actions*>::iterator it=gr_acts.begin();it!=gr_acts.end();++it){
delete *it;
}
}
}; // class SwitchS4
}; // namespace pfswitch13
#endif // _SWITCHS4_H_