Permalink
Browse files

plugin: yaml_config

  • Loading branch information...
akoepsel committed Nov 9, 2017
1 parent 93320e6 commit 6a89f563786755a23407c5ec458d993bc9f7a524
Showing with 2,038 additions and 26 deletions.
  1. +23 −0 config/plugin_yaml_config.m4
  2. +3 −0 config/plugins.m4
  3. +1 −1 libs/rofl-common
  4. +3 −0 src/xdpd/management/plugins/Makefile.am
  5. +24 −20 src/xdpd/management/plugins/config/config.cc
  6. +9 −4 src/xdpd/management/plugins/config/config.h
  7. +8 −0 src/xdpd/management/plugins/plugin_manager_loader.cc
  8. +22 −0 src/xdpd/management/plugins/yaml_config/Makefile.am
  9. +5 −0 src/xdpd/management/plugins/yaml_config/Plugin.am
  10. +10 −0 src/xdpd/management/plugins/yaml_config/interfaces/Makefile.am
  11. +163 −0 src/xdpd/management/plugins/yaml_config/interfaces/interfaces_scope.cc
  12. +50 −0 src/xdpd/management/plugins/yaml_config/interfaces/interfaces_scope.h
  13. +73 −0 src/xdpd/management/plugins/yaml_config/interfaces/nf_scope.cc
  14. +41 −0 src/xdpd/management/plugins/yaml_config/interfaces/nf_scope.h
  15. +12 −0 src/xdpd/management/plugins/yaml_config/openflow/Makefile.am
  16. +203 −0 src/xdpd/management/plugins/yaml_config/openflow/lsi_connections.cc
  17. +59 −0 src/xdpd/management/plugins/yaml_config/openflow/lsi_connections.h
  18. +293 −0 src/xdpd/management/plugins/yaml_config/openflow/lsi_scope.cc
  19. +53 −0 src/xdpd/management/plugins/yaml_config/openflow/lsi_scope.h
  20. +39 −0 src/xdpd/management/plugins/yaml_config/openflow/openflow_scope.cc
  21. +43 −0 src/xdpd/management/plugins/yaml_config/openflow/openflow_scope.h
  22. +36 −0 src/xdpd/management/plugins/yaml_config/root_scope.cc
  23. +49 −0 src/xdpd/management/plugins/yaml_config/root_scope.h
  24. +245 −0 src/xdpd/management/plugins/yaml_config/scope.cc
  25. +173 −0 src/xdpd/management/plugins/yaml_config/scope.h
  26. +10 −0 src/xdpd/management/plugins/yaml_config/system/Makefile.am
  27. +93 −0 src/xdpd/management/plugins/yaml_config/system/system_scope.cc
  28. +34 −0 src/xdpd/management/plugins/yaml_config/system/system_scope.h
  29. +94 −0 src/xdpd/management/plugins/yaml_config/xdpd.yaml
  30. +62 −0 src/xdpd/management/plugins/yaml_config/yaml_config.cc
  31. +89 −0 src/xdpd/management/plugins/yaml_config/yaml_config.h
  32. +16 −1 src/xdpd/openflow/openflow_switch.cc
@@ -0,0 +1,23 @@
#Define ALWAYS WITH_MGMT_$PLUGIN
AC_DEFINE(WITH_MGMT_YAML_CONFIG)
#LIB checks
AC_LANG_PUSH([C++])
PKG_CHECK_MODULES([YAML_CPP], [yaml-cpp], [have_yaml_cpp=yes], AC_MSG_ERROR([libyaml-cpp not found.]))
if (test "${have_yaml_cpp}" = "yes"); then
CXXFLAGS+=" $YAML_CPP_CFLAGS"
LIBS+=" $YAML_CPP_LIBS"
fi
AC_LANG_POP([C++])
#Add files
AC_CONFIG_FILES([
src/xdpd/management/plugins/yaml_config/Makefile
src/xdpd/management/plugins/yaml_config/interfaces/Makefile
src/xdpd/management/plugins/yaml_config/openflow/Makefile
src/xdpd/management/plugins/yaml_config/system/Makefile
])
View
@@ -57,6 +57,9 @@ touch $srcdir/src/xdpd/management/plugins/pm_timestamp.h
#CONFIG
ADD_PLUGIN(config)
#YAML
ADD_PLUGIN(yaml_config)
#QMF
ADD_PLUGIN(qmf)
Submodule rofl-common updated 36 files
+2 −2 config/debug.m4
+1 −0 examples/ethswctld/cdaemon.h
+13 −16 examples/ethswctld/cetherswitch.cc
+1 −1 examples/ethswctld/cetherswitch.h
+6 −9 examples/ethswctld/cfibentry.cc
+1 −1 examples/ethswctld/cfibentry.h
+6 −9 examples/ethswctld/cflowentry.cc
+1 −1 examples/ethswctld/cflowentry.h
+1 −0 examples/ethswctld/cunixenv.h
+11 −68 src/rofl/common/crofbase.cc
+18 −52 src/rofl/common/crofbase.h
+35 −126 src/rofl/common/crofchan.h
+153 −243 src/rofl/common/crofconn.cc
+44 −84 src/rofl/common/crofconn.h
+2 −7 src/rofl/common/crofctl.cc
+0 −33 src/rofl/common/crofctl.h
+12 −16 src/rofl/common/crofdpt.cc
+0 −30 src/rofl/common/crofdpt.h
+126 −133 src/rofl/common/crofsock.cc
+7 −22 src/rofl/common/crofsock.h
+32 −180 src/rofl/common/cthread.cpp
+18 −154 src/rofl/common/cthread.hpp
+5 −44 src/rofl/common/ctimer.hpp
+0 −18 src/rofl/common/locking.hpp
+2 −0 src/rofl/common/openflow/cofmatch.h
+9 −14 test/rofl/common/crofbase/crofbasetest.cpp
+4 −18 test/rofl/common/crofbase/crofbasetest.hpp
+2 −2 test/rofl/common/crofchan/Makefile.am
+114 −91 test/rofl/common/crofchan/crofchantest.cpp
+2 −10 test/rofl/common/crofchan/crofchantest.hpp
+2 −17 test/rofl/common/crofconn/crofconntest.cpp
+0 −4 test/rofl/common/crofconn/crofconntest.hpp
+2 −10 test/rofl/common/crofsock/crofsocktest.cpp
+0 −1 test/rofl/common/crofsock/crofsocktest.hpp
+4 −6 test/rofl/common/cthread/cthread_test.cc
+3 −5 test/rofl/common/cthread/cthread_test.h
@@ -23,6 +23,9 @@ AM_CXXFLAGS = -I$(top_srcdir)/src/
#Config
include config/Plugin.am
#Yaml
include yaml_config/Plugin.am
#QMF
include qmf/Plugin.am
@@ -23,7 +23,7 @@ void config::get_config_file_contents(Config* cfg){
std::string conf_file;
if(!system_manager::is_option_set(CONFIG_FILE_OPT_FULL_NAME)){
XDPD_ERR(CONF_PLUGIN_ID "No configuration file specified either via -c or --config-file\n");
XDPD_INFO(CONF_PLUGIN_ID "No configuration file specified either via -c or --config-file\n");
throw eConfParamNotFound();
}
@@ -41,29 +41,33 @@ void config::get_config_file_contents(Config* cfg){
}
void config::init(){
Config* cfg = new Config;
root_scope* root = new root_scope();
try {
Config* cfg = new Config;
root_scope* root = new root_scope();
//Dry run
XDPD_DEBUG_VERBOSE(CONF_PLUGIN_ID "Starting dry-run\n");
get_config_file_contents(cfg);
root->execute(*cfg,true);
delete cfg;
delete root;
//Unless test-config is set, execute the config
if(!system_manager::is_test_run()) {
//Execute
cfg = new Config;
root = new root_scope();
//Dry run
XDPD_DEBUG_VERBOSE(CONF_PLUGIN_ID "Starting dry-run\n");
get_config_file_contents(cfg);
XDPD_DEBUG_VERBOSE(CONF_PLUGIN_ID "Starting real execution\n");
root->execute(*cfg);
root->execute(*cfg,true);
delete cfg;
delete root;
//Unless test-config is set, execute the config
if(!system_manager::is_test_run()) {
//Execute
cfg = new Config;
root = new root_scope();
get_config_file_contents(cfg);
XDPD_DEBUG_VERBOSE(CONF_PLUGIN_ID "Starting real execution\n");
root->execute(*cfg);
delete cfg;
delete root;
}
} catch (eConfParamNotFound& e) {
// let other plugins continue to work
}
}
@@ -25,7 +25,7 @@
namespace xdpd {
//Macro for C logging
#define CONF_PLUGIN_ID "[xdpd][config] "
#define CONF_PLUGIN_ID "[xdpd][plugins][config] "
/**
* @brief libconfig based configuration plugin
@@ -50,9 +50,14 @@ class config : public plugin {
};
virtual std::string get_driver_extra_params(void){
libconfig::Config cfg;
get_config_file_contents(&cfg);
return system_scope::get_driver_extra_params(cfg);
try {
libconfig::Config cfg;
get_config_file_contents(&cfg);
return system_scope::get_driver_extra_params(cfg);
} catch (eConfParamNotFound& e) {
// let other plugins continue to work
return std::string("");
}
}
virtual std::string get_name(void){
@@ -23,6 +23,9 @@ using namespace xdpd;
#ifdef WITH_MGMT_CONFIG
#include "config/config.h"
#endif
#ifdef WITH_MGMT_YAML_CONFIG
#include "yaml_config/yaml_config.h"
#endif
#ifdef WITH_MGMT_QMF
#include "qmf/qmfagent.h"
#endif
@@ -51,6 +54,11 @@ void plugin_manager::pre_init(){
//Register CONFIG
register_plugin(new config());
#endif
#ifdef WITH_MGMT_YAML_CONFIG
//Register YAML_CONFIG
register_plugin(new xdpd::plugins::yaml_config::yaml_config());
#endif
#ifdef WITH_MGMT_QMF
//Register QMF
@@ -0,0 +1,22 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS=interfaces openflow system
#Library MUST BE named libxdpd_mgmt_PLUGIN_NAME.la
noinst_LTLIBRARIES = libxdpd_mgmt_yaml_config.la
libxdpd_mgmt_yaml_config_la_SOURCES = \
scope.cc \
root_scope.cc \
yaml_config.cc
libxdpd_mgmt_yaml_config_la_LIBADD = \
interfaces/libxdpd_mgmt_yaml_config_interfaces.la\
openflow/libxdpd_mgmt_yaml_config_openflow.la\
system/libxdpd_mgmt_yaml_config_system.la\
-lyaml-cpp
AM_CXXFLAGS = -I$(top_srcdir)/src/
sysconf_DATA = xdpd.yaml
@@ -0,0 +1,5 @@
#Always add the library CONDITIONALLY
if WITH_MGMT_YAML_CONFIG
libxdpd_mgmt_plugins_la_LIBADD += yaml_config/libxdpd_mgmt_yaml_config.la
endif
@@ -0,0 +1,10 @@
MAINTAINERCLEANFILES = Makefile.in
noinst_LTLIBRARIES = libxdpd_mgmt_yaml_config_interfaces.la
libxdpd_mgmt_yaml_config_interfaces_la_SOURCES = \
interfaces_scope.cc \
nf_scope.cc
libxdpd_mgmt_yaml_config_interfaces_la_LIBADD =
AM_CXXFLAGS=-I$(top_srcdir)/src/
@@ -0,0 +1,163 @@
#include "interfaces_scope.h"
#include <list>
#include <vector>
#include <stdlib.h>
#include <inttypes.h>
#include <rofl/datapath/pipeline/openflow/openflow1x/pipeline/of1x_pipeline.h>
#include "../../../switch_manager.h"
#include "../../../port_manager.h"
#include "../../../../openflow/openflow_switch.h"
#include "nf_scope.h"
#include "../yaml_config.h"
using namespace xdpd::plugins::yaml_config;
using namespace rofl;
//Constants
#define BLACKLIST "blacklist"
#define NF "nf"
#define VIRTUAL "virtual"
#define VLINK_LEFT "left"
#define VLINK_RIGHT "right"
#define VLINK_PORTNAME "portname"
#define VLINK_LSI "lsi"
#define VLINK_DESCRIPTION "description"
interfaces_scope::interfaces_scope(scope* parent):scope("interfaces", parent, false){
//Register parameters
register_parameter(BLACKLIST);
//Register subscopes
//Subscopes are logical switch elements so will be captured on pre_validate hook
register_priority_subscope(new nf_scope(this), 2, false);
register_subscope(new virtual_ifaces_scope(this));
}
void interfaces_scope::post_validate(YAML::Node& node, bool dry_run){
//Update cache
blacklisted.clear();
//If the configuration has a blacklist port
if(node[BLACKLIST] && node[BLACKLIST].IsSequence()){
YAML::Node blacklist = node[BLACKLIST];
for (auto iface : blacklist) {
std::string port(iface.as<std::string>());
//Check for port existance
if(port_manager::exists(port) == false){
XDPD_ERR(YAML_PLUGIN_ID "%s: attempting to blacklist an invalid port '%s'. Port does not exist!\n", BLACKLIST, port.c_str());
throw eYamlConfParseError();
}
//Blacklist
blacklisted.insert(port);
//If it is not dry run, then really blacklist it
if(!dry_run){
port_manager::blacklist(port);
}
}
}
}
virtual_ifaces_scope::virtual_ifaces_scope(scope* parent):scope("virtual", parent, false){
//Register subscopes
//Subscopes are logical switch elements so will be captured on pre_validate hook
}
void virtual_ifaces_scope::post_validate(YAML::Node& node, bool dry_run){
//If the configuration has virtual links
if(node[VIRTUAL] && node[VIRTUAL].IsMap()){
for (auto vlink : node[VIRTUAL]) {
std::string vlink_name = vlink.first.as<std::string>();
// port_name1
std::string port_name1;
if ((vlink.second[VLINK_LEFT]) && (vlink.second[VLINK_LEFT][VLINK_PORTNAME])) {
port_name1 = vlink.second[VLINK_LEFT][VLINK_PORTNAME].as<std::string>();
}
// lsi_name1
std::string lsi_name1;
if ((vlink.second[VLINK_LEFT]) && (vlink.second[VLINK_LEFT][VLINK_LSI])) {
lsi_name1 = vlink.second[VLINK_LEFT][VLINK_LSI].as<std::string>();
}
// port_name2
std::string port_name2;
if ((vlink.second[VLINK_RIGHT]) && (vlink.second[VLINK_RIGHT][VLINK_PORTNAME])) {
port_name2 = vlink.second[VLINK_RIGHT][VLINK_PORTNAME].as<std::string>();
}
// lsi_name2
std::string lsi_name2;
if ((vlink.second[VLINK_RIGHT]) && (vlink.second[VLINK_RIGHT][VLINK_LSI])) {
lsi_name2 = vlink.second[VLINK_RIGHT][VLINK_LSI].as<std::string>();
}
if (port_name1.empty()) {
XDPD_ERR(YAML_PLUGIN_ID "%s: no left port for virtual link defined\n", vlink_name.c_str());
throw eYamlConfParseError();
}
if(port_manager::exists(port_name1) == true){
XDPD_ERR(YAML_PLUGIN_ID "%s: port %s already exists\n", vlink_name.c_str(), port_name1.c_str());
throw eYamlConfParseError();
}
if (lsi_name1.empty()) {
XDPD_ERR(YAML_PLUGIN_ID "%s: no left lsi for virtual link defined\n", vlink_name.c_str());
throw eYamlConfParseError();
}
if (port_name2.empty()) {
XDPD_ERR(YAML_PLUGIN_ID "%s: no right port for virtual link defined\n", vlink_name.c_str());
throw eYamlConfParseError();
}
if(port_manager::exists(port_name2) == true){
XDPD_ERR(YAML_PLUGIN_ID "%s: port %s already exists\n", vlink_name.c_str(), port_name2.c_str());
throw eYamlConfParseError();
}
if (lsi_name2.empty()) {
XDPD_ERR(YAML_PLUGIN_ID "%s: no right lsi for virtual link defined\n", vlink_name.c_str());
throw eYamlConfParseError();
}
//Complete vlink
if(!dry_run){
uint64_t dpid1, dpid2;
//Recover switches by name
try{
dpid1 = switch_manager::get_switch_dpid(lsi_name1);
}catch(eOfSmDoesNotExist& e){
XDPD_ERR(YAML_PLUGIN_ID "%s: unable to create virtual link %s. LSI '%s' does not exist.\n",
VIRTUAL, vlink_name.c_str(), lsi_name1.c_str());
throw eYamlConfParseError();
}
//Recover switches by name
try{
dpid2 = switch_manager::get_switch_dpid(lsi_name2);
}catch(eOfSmDoesNotExist& e){
XDPD_ERR(YAML_PLUGIN_ID "%s: unable to create virtual link %s. LSI '%s' does not exist.\n",
VIRTUAL, vlink_name.c_str(), lsi_name2.c_str());
throw eYamlConfParseError();
}
unsigned int port_num1 = 0;
unsigned int port_num2 = 0;
//Call port manager API
port_manager::connect_switches(dpid1, &port_num1, port_name1, dpid2, &port_num2, port_name2);
}
}
}
}
Oops, something went wrong.

0 comments on commit 6a89f56

Please sign in to comment.