-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controllers management #93
base: integration-0.8
Are you sure you want to change the base?
Changes from 18 commits
9bcb4e1
f36b843
88efc5d
978ca72
00f592c
16a2f39
ad421d6
d46f6f6
1ec0b91
9f334e9
63f7247
f7a42b0
1902f12
73be2e2
d4ee5e7
5448b49
302573f
34a16a1
2f5295d
95ad31b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,102 @@ void lsi_groups(const http::server::request &req, | |
rep.content = json_spirit::write(wrap, true); | ||
} | ||
|
||
void list_ctls(const http::server::request &req, http::server::reply &rep, boost::cmatch& grps){ | ||
std::string lsi_name; | ||
uint64_t dpid; | ||
std::list<rofl::cctlid> list; | ||
json_spirit::Object table; | ||
|
||
//Perform security checks | ||
if(!authorised(req,rep)) return; | ||
|
||
lsi_name = std::string(grps[1]); | ||
|
||
// Get dpid | ||
if(!switch_manager::exists_by_name(lsi_name)){ | ||
//Throw 404 | ||
std::stringstream ss; | ||
ss<<"Invalid lsi '"<<lsi_name<<"'"; | ||
rep.content = ss.str(); | ||
rep.status = http::server::reply::not_found; | ||
return; | ||
} | ||
dpid = switch_manager::get_switch_dpid(lsi_name); | ||
|
||
try{ | ||
switch_manager::list_ctls(dpid, &list); | ||
}catch(...){ | ||
throw "Unable to get list of ctls from lsi"; | ||
} | ||
|
||
//Return data | ||
std::list<std::string> list_str; | ||
for(std::list<rofl::cctlid>::iterator it = list.begin(); it != list.end(); it++){ | ||
std::stringstream ss_tmp; | ||
ss_tmp << it->get_ctlid(); | ||
list_str.push_back(ss_tmp.str()); | ||
} | ||
|
||
json_spirit::Value ids_(list_str.begin(), list_str.end()); | ||
table.push_back(json_spirit::Pair("controller-ids", ids_)); | ||
rep.content = json_spirit::write(table, true); | ||
} | ||
|
||
void show_ctl(const http::server::request &req, http::server::reply &rep, boost::cmatch& grps){ | ||
std::string lsi_name; //, ctl_id; | ||
uint64_t dpid, ctl_id; | ||
controller_snapshot ctl_info; | ||
json_spirit::Object j_wrap, j_ctl, j_list; | ||
|
||
//Perform security checks | ||
if(!authorised(req,rep)) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra space. Authorisation here not needed. |
||
|
||
lsi_name = std::string(grps[1]); | ||
ctl_id = atoi(std::string(grps[2]).c_str()); | ||
|
||
|
||
// Get dpid | ||
if(!switch_manager::exists_by_name(lsi_name)){ | ||
//Throw 404 | ||
std::stringstream ss; | ||
ss<<"Invalid lsi '"<<lsi_name<<"'"; | ||
rep.content = ss.str(); | ||
rep.status = http::server::reply::not_found; | ||
return; | ||
} | ||
|
||
dpid = switch_manager::get_switch_dpid(lsi_name); | ||
|
||
try{ | ||
switch_manager::get_controller_info(dpid, ctl_id, ctl_info); | ||
}catch(...){ | ||
throw "Unable to get Controller info for lsi"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this go as part of the |
||
} | ||
|
||
j_ctl.push_back(json_spirit::Pair("id", ctl_info.id)); | ||
j_ctl.push_back(json_spirit::Pair("channel-status", ctl_info.get_status_str())); | ||
j_ctl.push_back(json_spirit::Pair("mode", ctl_info.get_role_str())); | ||
|
||
std::list<controller_conn_snapshot>::const_iterator it; | ||
for(it=ctl_info.conn_list.begin(); it != ctl_info.conn_list.end(); ++it){ | ||
json_spirit::Object j_conn; | ||
j_conn.push_back(json_spirit::Pair("protocol-type", it->get_proto_type_str())); | ||
j_conn.push_back(json_spirit::Pair("ip", it->ip)); | ||
j_conn.push_back(json_spirit::Pair("port", it->port)); | ||
|
||
std::stringstream ss; | ||
ss << it->id; | ||
j_list.push_back(json_spirit::Pair(ss.str(), j_conn)); | ||
|
||
} | ||
|
||
j_ctl.push_back(json_spirit::Pair("connections", j_list)); | ||
|
||
//Return data | ||
j_wrap.push_back(json_spirit::Pair("Controller", j_ctl)); | ||
rep.content = json_spirit::write(j_wrap, true); | ||
} | ||
|
||
} //namespace get | ||
|
||
|
||
|
@@ -358,6 +454,87 @@ void create_lsi(const http::server::request &req, http::server::reply &rep, boos | |
//There is no need to return anything | ||
} | ||
|
||
|
||
void add_ctl(const http::server::request &req, http::server::reply &rep, boost::cmatch& grps){ | ||
|
||
//call switch_manager to add a new controller to the LSI | ||
// get IP & port from the req parameter (json?) | ||
// check IP & port (if there is already a controller there, send error message) | ||
std::string proto, ip, port; | ||
enum rofl::csocket::socket_type_t socket_type; | ||
rofl::cparams socket_params; | ||
json_spirit::Object table; | ||
uint64_t assigned_id; | ||
|
||
//Perform security checks | ||
if(!authorised(req,rep)) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra space |
||
|
||
std::string lsi_name = std::string(grps[1]); | ||
|
||
//Check if LSI exists; | ||
if(!switch_manager::exists_by_name(lsi_name)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space |
||
//Throw 404 | ||
std::stringstream ss; | ||
ss<<"Invalid lsi '"<<lsi_name<<"'"; | ||
rep.content = ss.str(); | ||
rep.status = http::server::reply::not_found; | ||
return; | ||
} | ||
|
||
// Get dpid check for failure | ||
uint64_t dpid = switch_manager::get_switch_dpid(lsi_name); | ||
|
||
// Parse data (protocol, IP & port) | ||
try{ | ||
//Parse the input | ||
json_spirit::Value val; | ||
|
||
//First object must be "lsi" | ||
json_spirit::read(req.content, val); | ||
|
||
json_spirit::Object obj = val.get_obj(); | ||
obj = json_spirit::find_value(obj, "ctl").get_obj(); | ||
|
||
//Fill in parameters | ||
proto = json_spirit::find_value(obj, "proto").get_str(); | ||
ip = json_spirit::find_value(obj, "ip").get_str(); | ||
port = json_spirit::find_value(obj, "port").get_str(); | ||
|
||
}catch(...){ | ||
std::stringstream ss; | ||
ss<<"Unable to parse arguments for add controller"; | ||
rep.content = ss.str(); | ||
rep.status = http::server::reply::bad_request; | ||
return; | ||
} | ||
|
||
|
||
//TODO Check parameters received (proto, ip & port) | ||
if ( proto == "tcp" ){ | ||
socket_type = rofl::csocket::SOCKET_TYPE_PLAIN; | ||
} else { | ||
// TODO Other types not yet supported (SOCKET_TYPE_OPENSSL) | ||
std::stringstream ss; | ||
ss<<"Invalid protocol '"<<lsi_name<<"'"; | ||
rep.content = ss.str(); | ||
rep.status = http::server::reply::bad_request; | ||
return; | ||
} | ||
socket_params = rofl::csocket::get_default_params(socket_type); | ||
socket_params.set_param(rofl::csocket::PARAM_KEY_REMOTE_HOSTNAME) = ip; | ||
socket_params.set_param(rofl::csocket::PARAM_KEY_REMOTE_PORT) = port; | ||
|
||
try{ | ||
assigned_id = switch_manager::connect_to_ctl(dpid, socket_type, socket_params); | ||
}catch(...){ | ||
throw "Unable to add controller to lsi"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong identation. This should go to |
||
} | ||
|
||
//Return assigned ID | ||
table.push_back(json_spirit::Pair("assigned id", assigned_id)); | ||
rep.content = json_spirit::write(table, true); | ||
} | ||
|
||
} //namespace put | ||
|
||
namespace delete_{ | ||
|
@@ -395,6 +572,42 @@ void destroy_switch(const http::server::request &req, http::server::reply &rep, | |
} | ||
} | ||
|
||
void rem_ctl(const http::server::request &req, http::server::reply &rep, boost::cmatch& grps){ | ||
|
||
std::string lsi_name; | ||
std::string ctlid_str; | ||
uint64_t dpid, ctl_id; | ||
|
||
//Perform security checks | ||
if(!authorised(req,rep)) return; | ||
|
||
lsi_name = std::string(grps[1]); | ||
ctlid_str = std::string(grps[2]); | ||
|
||
//Check if LSI exists; | ||
if(!switch_manager::exists_by_name(lsi_name)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space |
||
//Throw 404 | ||
std::stringstream ss; | ||
ss<<"Invalid lsi '"<<lsi_name<<"'"; | ||
rep.content = ss.str(); | ||
rep.status = http::server::reply::not_found; | ||
return; | ||
} | ||
|
||
// Get dpid | ||
dpid = switch_manager::get_switch_dpid(lsi_name); | ||
|
||
// get Ctlid | ||
ctl_id = atoi(ctlid_str.c_str()); | ||
rofl::cctlid ctlid(ctl_id); | ||
|
||
try{ | ||
switch_manager::disconnect_from_ctl(dpid, ctlid); | ||
}catch(...){ | ||
throw "Unable to remove controller from lsi"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem as before. indentation as should be the return body of HTTP |
||
} | ||
} | ||
|
||
} //namespace delete | ||
} //namespace controllers | ||
} //namespace xdpd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space. Authorisization here is not needed