Last active
August 29, 2015 14:03
-
-
Save thehajime/8592528bca9482c6e75b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/Makefile.am b/src/Makefile.am | |
| index 632ac24..c5603c9 100644 | |
| --- a/src/Makefile.am | |
| +++ b/src/Makefile.am | |
| @@ -19,31 +19,35 @@ nox_core_SOURCES = \ | |
| builtin/component.cc \ | |
| builtin/connection-manager.cc \ | |
| builtin/deployer.cc \ | |
| - builtin/dso-deployer.cc \ | |
| builtin/event-dispatcher.cc \ | |
| builtin/kernel.cc \ | |
| builtin/static-deployer.cc \ | |
| nox_main.cc | |
| +# builtin/dso-deployer.cc \ | |
| CLEANFILES = | |
| nox_core_CPPFLAGS = \ | |
| - $(AM_CPPFLAGS) | |
| + $(AM_CPPFLAGS) \ | |
| + -I$(top_srcdir)/src/coreapps | |
| -nox_core_LDFLAGS = \ | |
| - $(AM_LDFLAGS) -dlopen force | |
| +#nox_core_LDFLAGS = \ | |
| +# $(AM_LDFLAGS) | |
| + | |
| +nox_core_LDFLAGS = -static | |
| nox_core_LDADD = \ | |
| $(LDADD) \ | |
| - $(builddir)/lib/libnoxcore.la \ | |
| + $(builddir)/lib/libnoxcore.a \ | |
| + $(builddir)/coreapps/openflow/libopenflow_manager.a \ | |
| + $(builddir)/coreapps/switch/libswitch.a \ | |
| $(BOOST_THREAD_LIB) \ | |
| $(BOOST_FILESYSTEM_LIB) \ | |
| $(BOOST_SYSTEM_LIB) \ | |
| - $(OPENSSL_LIBS) \ | |
| - $(LIBADD_DL) \ | |
| - $(LIBADD_DLOPEN) \ | |
| - $(LIBADD_SHL_LOAD) \ | |
| - $(LIBLTDL) | |
| + $(BOOST_SERIALIZATION_LIB) \ | |
| + $(OPENSSL_LIBS) | |
| + | |
| +# $(TBB_LIBS) | |
| nox_core_DEPENDENCIES = | |
| @@ -51,7 +55,6 @@ nox_core_DEPENDENCIES = | |
| # prerequisite you have to pass '--enable-ltdl' and '--enable-static' | |
| # for the configure. Plus enable the static linkage of the nox_core | |
| # binary by uncommenting the next line: | |
| -#nox_core_LDFLAGS += -static | |
| # | |
| # Then to define the application libraries to link to the nox_core | |
| # binary, per library append a) '-dlopen path/to/library.la' to | |
| diff --git a/src/builtin/dso-deployer.cc b/src/builtin/dso-deployer.cc | |
| deleted file mode 100644 | |
| index b0b96e8..0000000 | |
| --- a/src/builtin/dso-deployer.cc | |
| +++ /dev/null | |
| @@ -1,333 +0,0 @@ | |
| -/* Copyright 2008 (C) Nicira, Inc. | |
| - * | |
| - * This file is part of NOX. | |
| - * | |
| - * NOX is free software: you can redistribute it and/or modify | |
| - * it under the terms of the GNU General Public License as published by | |
| - * the Free Software Foundation, either version 3 of the License, or | |
| - * (at your option) any later version. | |
| - * | |
| - * NOX is distributed in the hope that it will be useful, | |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| - * GNU General Public License for more details. | |
| - * | |
| - * You should have received a copy of the GNU General Public License | |
| - * along with NOX. If not, see <http://www.gnu.org/licenses/>. | |
| - */ | |
| -#include "dso-deployer.hh" | |
| - | |
| -#include <dlfcn.h> | |
| - | |
| -#include <boost/bind.hpp> | |
| -#include <boost/filesystem.hpp> | |
| -#include <boost/foreach.hpp> | |
| -#include <boost/property_tree/ptree.hpp> | |
| -#include <boost/property_tree/json_parser.hpp> | |
| - | |
| -#include "fault.hh" | |
| -#include "vlog.hh" | |
| - | |
| -using namespace std; | |
| -using namespace vigil; | |
| - | |
| -static Vlog_module lg("dso-deployer"); | |
| - | |
| -static lt_dlhandle | |
| -open_library(const char* library, const char** error_msg) | |
| -{ | |
| - lt_dlhandle h = 0; | |
| - lt_dladvise advise; | |
| - if (!lt_dladvise_init(&advise) | |
| - && !lt_dladvise_ext(&advise) | |
| - && !lt_dladvise_global(&advise)) | |
| - h = lt_dlopenadvise(library, advise); | |
| - lt_dladvise_destroy(&advise); | |
| - //lt_dlhandle h = lt_dlopenext(library); | |
| - *error_msg = h ? "" : lt_dlerror(); | |
| - return h; | |
| -} | |
| - | |
| -DSO_deployer::DSO_deployer(const Component_context* ctxt, | |
| - const list<string>& lib_dirs) | |
| - : Component(ctxt), lib_dirs(lib_dirs) | |
| -{ | |
| - namespace fs = boost::filesystem; | |
| - namespace pt = boost::property_tree; | |
| - | |
| - /* Initialize preloaded symbol table */ | |
| - LTDL_SET_PRELOADED_SYMBOLS(); | |
| - | |
| - /* Initialize the libtool dynamic library loading facilities */ | |
| - if (lt_dlinit()) | |
| - { | |
| - throw runtime_error("lt_dlinit() failed: " + | |
| - demangle_undefined_symbol(lt_dlerror())); | |
| - } | |
| - | |
| - if (!lt_dlopen(0)) | |
| - { | |
| - throw runtime_error("lt_dlopen() for the main() failed: " + | |
| - demangle_undefined_symbol(lt_dlerror())); | |
| - } | |
| - | |
| - list<fs::path> description_files; | |
| - BOOST_FOREACH(string directory, lib_dirs) | |
| - { | |
| - list<fs::path> results = scan(directory); | |
| - description_files.insert(description_files.end(), | |
| - results.begin(), results.end()); | |
| - } | |
| - | |
| - BOOST_FOREACH(fs::path& config_path, description_files) | |
| - { | |
| - try | |
| - { | |
| - // read the config file into config_root | |
| - pt::ptree root; | |
| - pt::read_json(config_path.string(), root); | |
| - | |
| - BOOST_FOREACH(const pt::ptree::value_type& component, root) | |
| - { | |
| - const std::string& name = component.first; | |
| - Component_context* ctxt = | |
| - new DSO_component_context(name, config_path.string()); | |
| - if (uninstalled_contexts.find(ctxt->get_name()) == | |
| - uninstalled_contexts.end()) | |
| - { | |
| - uninstalled_contexts[ctxt->get_name()] = ctxt; | |
| - VLOG_DBG(lg, "Component '%s' scanned.", ctxt->get_name().c_str()); | |
| - } | |
| - else | |
| - { | |
| - VLOG_ERR(lg, "Component '%s' declared multiple times.", | |
| - ctxt->get_name().c_str()); | |
| - delete ctxt; | |
| - } | |
| - } | |
| - } | |
| - catch (const bad_cast& e) | |
| - { | |
| - // Not a DSO component, skip. | |
| - continue; | |
| - } | |
| - catch (const pt::ptree_error& e) | |
| - { | |
| - VLOG_ERR(lg, "Cannot parse '%s': %s", config_path.string().c_str(), | |
| - e.what()); | |
| - } | |
| - } | |
| - | |
| - Kernel* kernel = Kernel::get_instance(); | |
| - | |
| - /* Cross-check they are no duplicate component definitions across | |
| - deployers. */ | |
| - BOOST_FOREACH(const Deployer* deployer, kernel->get_deployers()) | |
| - { | |
| - BOOST_FOREACH(Component_context* ctxt, deployer->get_contexts()) | |
| - { | |
| - Component_name_context_map::iterator i = | |
| - uninstalled_contexts.find(ctxt->get_name()); | |
| - if (i != uninstalled_contexts.end()) | |
| - { | |
| - VLOG_ERR(lg, "Component '%s' declared multiple times.", | |
| - ctxt->get_name().c_str()); | |
| - uninstalled_contexts.erase(i); | |
| - } | |
| - } | |
| - } | |
| - | |
| - /* Finally, register itself as a deployer responsible for DSO | |
| - components. */ | |
| - kernel->attach_deployer(this); | |
| -} | |
| - | |
| -DSO_deployer::~DSO_deployer() | |
| -{ | |
| - | |
| -} | |
| - | |
| -Component* | |
| -DSO_deployer::instantiate(const Component_context* ctxt, | |
| - const Path_list& lib_search_paths) | |
| -{ | |
| - return new DSO_deployer(ctxt, lib_search_paths); | |
| -} | |
| - | |
| -void | |
| -DSO_deployer::configure() | |
| -{ | |
| -} | |
| - | |
| -void | |
| -DSO_deployer::install() | |
| -{ | |
| -} | |
| - | |
| -DSO_deployer::Path_list | |
| -DSO_deployer::get_search_paths() const | |
| -{ | |
| - return lib_dirs; | |
| -} | |
| - | |
| -DSO_component_context::DSO_component_context(const Component_name& name, | |
| - const std::string& config_path) | |
| - : Component_context(name, config_path) | |
| -{ | |
| - using namespace boost; | |
| - | |
| - install_actions[DESCRIBED] = bind(&DSO_component_context::describe, this); | |
| - install_actions[LOADED] = bind(&DSO_component_context::load, this); | |
| - install_actions[FACTORY_INSTANTIATED] = | |
| - bind(&DSO_component_context::instantiate_factory, this); | |
| - install_actions[INSTANTIATED] = | |
| - bind(&DSO_component_context::instantiate, this); | |
| - install_actions[CONFIGURED] = bind(&DSO_component_context::configure, this); | |
| - install_actions[INSTALLED] = | |
| - bind(&DSO_component_context::install, this); | |
| - | |
| - library = properties.get<std::string>("library"); | |
| - | |
| - if (has("dependencies")) | |
| - { | |
| - BOOST_FOREACH(const std::string& dependency, | |
| - get_config_list("dependencies")) | |
| - { | |
| - dependencies.push_back(new Name_dependency(dependency)); | |
| - } | |
| - } | |
| -} | |
| - | |
| -void | |
| -DSO_component_context::describe() | |
| -{ | |
| - /* Dependencies were introduced in the constructor */ | |
| - current_state = DESCRIBED; | |
| -} | |
| - | |
| -void | |
| -DSO_component_context::load() | |
| -{ | |
| - namespace fs = boost::filesystem; | |
| - fs::path home_path(properties.get<std::string>("home_path")); | |
| - const char* error_msg; | |
| - | |
| - handle = open_library((home_path / library).string().c_str(), &error_msg); | |
| - string error(demangle_undefined_symbol(error_msg)); | |
| - | |
| - /* A little extra check for libtool build directory */ | |
| - if (!handle) | |
| - { | |
| - handle = open_library( | |
| - (home_path / ".libs" / library).string().c_str(), | |
| - &error_msg); | |
| - error = "'" + error + "' or '" + demangle_undefined_symbol(error_msg) + "'"; | |
| - } | |
| - | |
| - if (!handle) | |
| - { | |
| - current_state = ERROR; | |
| - error_message = "Cannot open a dynamic library: " + error; | |
| - } | |
| - else | |
| - { | |
| - current_state = LOADED; | |
| - } | |
| -} | |
| - | |
| -DSO_component_context::component_factory_function* | |
| -DSO_component_context::find_factory_function(const char* name) const | |
| -{ | |
| - component_factory_function* f = | |
| - reinterpret_cast<component_factory_function*>(lt_dlsym(handle, name)); | |
| - return f; | |
| -} | |
| - | |
| -static const string replace(const string& s, const char c, const string& n) | |
| -{ | |
| - string v = s; | |
| - while (true) | |
| - { | |
| - string::size_type p = v.find(c, 0); | |
| - if (p == string::npos) | |
| - { | |
| - return v; | |
| - } | |
| - | |
| - v = v.replace(p, 1, n); | |
| - } | |
| -} | |
| - | |
| -void | |
| -DSO_component_context::instantiate_factory() | |
| -{ | |
| - component_factory_function* f = 0; | |
| - | |
| - /* Prefer a factory function with the embedded component name, but if | |
| - that's not found, default to one without the name. */ | |
| - string function_with_component_name = | |
| - replace(library, '-', "_") + "_get_factory"; | |
| - | |
| - f = find_factory_function(function_with_component_name.c_str()); | |
| - if (!f) | |
| - { | |
| - f = find_factory_function("get_factory"); | |
| - } | |
| - if (!f) | |
| - { | |
| - current_state = ERROR; | |
| - error_message = library + " does not implement " + | |
| - function_with_component_name + "() nor get_factory() function"; | |
| - return; | |
| - } | |
| - | |
| - factory = f(); | |
| - interface = factory->get_interface(); | |
| - current_state = FACTORY_INSTANTIATED; | |
| -} | |
| - | |
| -void | |
| -DSO_component_context::instantiate() | |
| -{ | |
| - try | |
| - { | |
| - component = factory->instance(this); | |
| - current_state = INSTANTIATED; | |
| - } | |
| - catch (const std::exception& e) | |
| - { | |
| - error_message = e.what(); | |
| - current_state = ERROR; | |
| - } | |
| -} | |
| - | |
| -void | |
| -DSO_component_context::configure() | |
| -{ | |
| - try | |
| - { | |
| - component->configure(); | |
| - current_state = CONFIGURED; | |
| - } | |
| - catch (const std::exception& e) | |
| - { | |
| - error_message = e.what(); | |
| - current_state = ERROR; | |
| - } | |
| -} | |
| - | |
| -void | |
| -DSO_component_context::install() | |
| -{ | |
| - try | |
| - { | |
| - component->install(); | |
| - current_state = INSTALLED; | |
| - } | |
| - catch (const std::exception& e) | |
| - { | |
| - error_message = e.what(); | |
| - current_state = ERROR; | |
| - } | |
| -} | |
| - | |
| diff --git a/src/builtin/event-dispatcher.cc b/src/builtin/event-dispatcher.cc | |
| index 3114836..9058e8e 100644 | |
| --- a/src/builtin/event-dispatcher.cc | |
| +++ b/src/builtin/event-dispatcher.cc | |
| @@ -86,14 +86,15 @@ Event_dispatcher::install() | |
| for (std::size_t i = 1; i <= n_threads; i++) | |
| { | |
| VLOG_DBG(lg, "creating thread %zu", i); | |
| - tg.create_thread(boost::bind(&boost::asio::io_service::run, &io)); | |
| + // tg.create_thread(boost::bind(&boost::asio::io_service::run, &io)); | |
| } | |
| } | |
| void | |
| Event_dispatcher::join_all() | |
| { | |
| - tg.join_all(); | |
| + io.run(); | |
| +// tg.join_all(); | |
| } | |
| void | |
| diff --git a/src/coreapps/openflow/Makefile.am b/src/coreapps/openflow/Makefile.am | |
| index dbd7686..ba4e3f1 100644 | |
| --- a/src/coreapps/openflow/Makefile.am | |
| +++ b/src/coreapps/openflow/Makefile.am | |
| @@ -23,14 +23,14 @@ EXTRA_DIST = \ | |
| # $(AM_LDFLAGS) -export-dynamic \ | |
| # -version-info $(OPENFLOW_LIB_VERSION) | |
| -pkglib_LTLIBRARIES = \ | |
| - openflow_manager.la | |
| +lib_LIBRARIES = \ | |
| + libopenflow_manager.a | |
| -openflow_manager_la_CPPFLAGS = \ | |
| +libopenflow_manager_a_CPPFLAGS = \ | |
| $(AM_CPPFLAGS) \ | |
| -I$(top_srcdir)/src/coreapps | |
| -openflow_manager_la_SOURCES = \ | |
| +libopenflow_manager_a_SOURCES = \ | |
| openflow-manager.hh \ | |
| openflow-manager.cc \ | |
| openflow-datapath.hh \ | |
| @@ -43,15 +43,13 @@ openflow_manager_la_SOURCES = \ | |
| openflow-defs-1.0.hh \ | |
| openflow-1.0.cc | |
| -openflow_manager_la_LDFLAGS = \ | |
| - $(AM_LDFLAGS) -module \ | |
| - -version-info $(OPENFLOW_MANAGER_VERSION) | |
| +#libopenflow_manager_a_LDFLAGS = \ | |
| +# $(AM_LDFLAGS) -module \ | |
| +# -version-info $(OPENFLOW_MANAGER_VERSION) | |
| -openflow_manager_la_DEPENDENCIES = | |
| +libopenflow_manager_a_DEPENDENCIES = | |
| -openflow_manager_la_LIBADD = | |
| - | |
| -NOX_RUNTIMEFILES = meta.json | |
| +libopenflow_manager_a_LIBADD = | |
| all-local: nox-all-local | |
| clean-local: nox-clean-local | |
| diff --git a/src/coreapps/openflow/openflow-manager.cc b/src/coreapps/openflow/openflow-manager.cc | |
| index a7b6ae3..cf7e5ea 100644 | |
| --- a/src/coreapps/openflow/openflow-manager.cc | |
| +++ b/src/coreapps/openflow/openflow-manager.cc | |
| @@ -46,6 +46,12 @@ namespace openflow | |
| static Vlog_module lg("openflow-manager"); | |
| +Component* | |
| +Openflow_manager::instantiate(const Component_context* ctxt) | |
| +{ | |
| + return new Openflow_manager(ctxt); | |
| +} | |
| + | |
| Openflow_manager::Openflow_manager(const Component_context* ctxt) | |
| : Component(ctxt) | |
| { | |
| @@ -186,7 +192,7 @@ Openflow_manager::handle_echo_request(const Event& e) | |
| return STOP; | |
| } | |
| -REGISTER_COMPONENT(Simple_component_factory<Openflow_manager>, Openflow_manager); | |
| +//REGISTER_COMPONENT(Simple_component_factory<Openflow_manager>, Openflow_manager); | |
| } // namespace vigil | |
| } // namespace vigil | |
| diff --git a/src/coreapps/openflow/openflow-manager.hh b/src/coreapps/openflow/openflow-manager.hh | |
| index 3b7c1e3..da602c2 100644 | |
| --- a/src/coreapps/openflow/openflow-manager.hh | |
| +++ b/src/coreapps/openflow/openflow-manager.hh | |
| @@ -41,10 +41,12 @@ class Openflow_datapath; | |
| class Openflow_manager : public Component | |
| { | |
| public: | |
| - Openflow_manager(const Component_context* ctxt); | |
| + | |
| + static Component* instantiate(const Component_context* ctxt); | |
| void configure(); | |
| private: | |
| + Openflow_manager(const Component_context* ctxt); | |
| typedef boost::unordered_map<datapathid, boost::shared_ptr<Openflow_datapath> > | |
| Datapath_map; | |
| typedef std::set<boost::shared_ptr<Openflow_datapath> > Datapath_set; | |
| diff --git a/src/coreapps/switch/Makefile.am b/src/coreapps/switch/Makefile.am | |
| index ca25a3a..b108ef5 100644 | |
| --- a/src/coreapps/switch/Makefile.am | |
| +++ b/src/coreapps/switch/Makefile.am | |
| @@ -4,29 +4,24 @@ CONFIGURE_DEPENCIES = $(srcdir)/Makefile.am | |
| SWITCH_LIB_VERSION = 1:0:0 | |
| -EXTRA_DIST = \ | |
| - meta.json | |
| +pkglib_LIBRARIES = \ | |
| + libswitch.a | |
| -pkglib_LTLIBRARIES = \ | |
| - switch.la | |
| - | |
| -switch_la_CPPFLAGS = \ | |
| +libswitch_a_CPPFLAGS = \ | |
| $(AM_CPPFLAGS) \ | |
| $(TBB_CPPFLAGS) \ | |
| -I$(top_srcdir)/src/coreapps | |
| -switch_la_SOURCES = \ | |
| +libswitch_a_SOURCES = \ | |
| switch.cc | |
| -switch_la_LDFLAGS = \ | |
| - $(AM_LDFLAGS) -module \ | |
| - -version-info $(SWITCH_LIB_VERSION) | |
| - | |
| -switch_la_LIBADD = \ | |
| - $(TBB_LDFLAGS) \ | |
| - $(TBB_LIBS) | |
| +#libswitch_a_LDFLAGS = \ | |
| +# $(AM_LDFLAGS) -module \ | |
| +# -version-info $(SWITCH_LIB_VERSION) | |
| -NOX_RUNTIMEFILES = meta.json | |
| +#libswitch_a_LIBADD = \ | |
| +# $(TBB_LDFLAGS) \ | |
| +# $(TBB_LIBS) | |
| all-local: nox-all-local | |
| clean-local: nox-clean-local | |
| diff --git a/src/coreapps/switch/switch.cc b/src/coreapps/switch/switch.cc | |
| index 195e5eb..6dc5d49 100644 | |
| --- a/src/coreapps/switch/switch.cc | |
| +++ b/src/coreapps/switch/switch.cc | |
| @@ -16,76 +16,15 @@ | |
| * along with NOX. If not, see <http://www.gnu.org/licenses/>. | |
| */ | |
| -#include <cstring> | |
| -#include <netinet/in.h> | |
| -#include <stdexcept> | |
| -#include <stdint.h> | |
| -#include <string> | |
| -#include <boost/bind.hpp> | |
| -#include <boost/foreach.hpp> | |
| +#include "switch.hh" | |
| -#include <tbb/concurrent_hash_map.h> | |
| - | |
| -#include "assert.hh" | |
| -#include "component.hh" | |
| -#include "vlog.hh" | |
| - | |
| -#include "netinet++/datapathid.hh" | |
| -#include "netinet++/ethernetaddr.hh" | |
| -#include "netinet++/ethernet.hh" | |
| - | |
| -#include "openflow/openflow-event.hh" | |
| -#include "openflow/openflow-datapath-join-event.hh" | |
| -#include "openflow/openflow-datapath-leave-event.hh" | |
| - | |
| -using namespace vigil; | |
| -using namespace openflow; | |
| - | |
| -namespace | |
| +namespace apps | |
| { | |
| -Vlog_module lg("switch"); | |
| +Vlog_module lg_switch("switch"); | |
| -class Switch | |
| - : public Component | |
| -{ | |
| -public: | |
| - Switch(const Component_context* c) | |
| - : Component(c) | |
| - { | |
| - setup_flows = true; // default value | |
| - } | |
| - | |
| - void configure(); | |
| - | |
| - void install() {} | |
| - | |
| - Disposition handle_datapath_join(const Event&); | |
| - Disposition handle_datapath_leave(const Event&); | |
| - Disposition handle_packet_in(const Event&); | |
| - | |
| -private: | |
| - struct datapath_hasher { | |
| - static size_t hash(const datapathid& o) { | |
| - return boost::hash_value(o.as_host()); | |
| - } | |
| - static bool equal(const datapathid& o1, const datapathid& o2) | |
| - { | |
| - return o1 == o2; | |
| - } | |
| - }; | |
| - typedef boost::unordered_map<ethernetaddr, int> mac_table; | |
| - typedef tbb::concurrent_hash_map<datapathid, mac_table, datapath_hasher> mac_table_map; | |
| - | |
| - mac_table_map mac_tables; | |
| - | |
| - /* Set up a flow when we know the destination of a packet? This should | |
| - * ordinarily be true; it is only usefully false for debugging purposes. */ | |
| - bool setup_flows; | |
| -}; | |
| - | |
| -inline void | |
| +void | |
| Switch::configure() | |
| { | |
| if (ctxt->has("args")) { | |
| @@ -97,7 +36,7 @@ Switch::configure() | |
| } | |
| else | |
| { | |
| - VLOG_WARN(lg, "argument \"%s\" not supported", arg.c_str()); | |
| + VLOG_WARN(lg_switch, "argument \"%s\" not supported", arg.c_str()); | |
| } | |
| } | |
| } | |
| @@ -106,23 +45,32 @@ Switch::configure() | |
| register_handler("ofp_packet_in", (boost::bind(&Switch::handle_packet_in, this, _1))); | |
| } | |
| -inline Disposition | |
| +Component* | |
| +Switch::instantiate(const Component_context* ctxt) | |
| +{ | |
| + return new Switch(ctxt); | |
| +} | |
| + | |
| + | |
| +Disposition | |
| Switch::handle_datapath_join(const Event& e) | |
| { | |
| auto& dpje = assert_cast<const Openflow_datapath_join_event&>(e); | |
| - mac_tables.insert(std::make_pair(dpje.dp->id(), mac_table())); | |
| + //mac_tables.insert(std::make_pair(dpje.dp->id(), mac_table())); | |
| + mac_tables[dpje.dp->id()] = mac_table(); | |
| return CONTINUE; | |
| } | |
| -inline Disposition | |
| +Disposition | |
| Switch::handle_datapath_leave(const Event& e) | |
| { | |
| auto& dple = assert_cast<const Openflow_datapath_leave_event&>(e); | |
| + //mac_tables.erase(dple.dp->id()); | |
| mac_tables.erase(dple.dp->id()); | |
| return CONTINUE; | |
| } | |
| -inline Disposition | |
| +Disposition | |
| Switch::handle_packet_in(const Event& e) | |
| { | |
| auto ofe = assert_cast<const Openflow_event&>(e); | |
| @@ -139,9 +87,14 @@ Switch::handle_packet_in(const Event& e) | |
| return CONTINUE; | |
| } | |
| + /* | |
| mac_table_map::accessor accessor; | |
| mac_tables.find(accessor, dp.id()); | |
| auto& mac_table = accessor->second; | |
| + */ | |
| + | |
| + auto mac_tables_iter = mac_tables.find(dp.id()); | |
| + auto& mac_table = mac_tables_iter->second; | |
| // Learn the source MAC | |
| if (!flow.dl_src().is_multicast()) | |
| @@ -182,9 +135,9 @@ Switch::handle_packet_in(const Event& e) | |
| { | |
| if (pi.total_len() != boost::asio::buffer_size(pi.packet())) | |
| { | |
| - /* Control path didn't buffer the packet and didn't send us | |
| - * the whole thing--what gives? */ | |
| - VLOG_DBG(lg, "total_len=%u data_len=%zu\n", | |
| + // Control path didn't buffer the packet and didn't send us | |
| + // the whole thing--what gives? | |
| + VLOG_DBG(lg_switch, "total_len=%u data_len=%zu\n", | |
| pi.total_len(), boost::asio::buffer_size(pi.packet())); | |
| return CONTINUE; | |
| } | |
| @@ -198,7 +151,6 @@ Switch::handle_packet_in(const Event& e) | |
| } | |
| return CONTINUE; | |
| } | |
| +} | |
| +//REGISTER_COMPONENT(Simple_component_factory<Switch>, Switch); | |
| -REGISTER_COMPONENT(Simple_component_factory<Switch>, Switch); | |
| - | |
| -} // unnamed namespace | |
| diff --git a/src/etc/nox.meta.json b/src/etc/nox.meta.json | |
| index 0dc84be..6738881 100644 | |
| --- a/src/etc/nox.meta.json | |
| +++ b/src/etc/nox.meta.json | |
| @@ -1,4 +1,8 @@ | |
| { | |
| + "openflow-manager": { | |
| + }, | |
| + "switch": { | |
| + }, | |
| "dso-deployer": { | |
| }, | |
| "connection-manager": { | |
| diff --git a/src/include/dso-deployer.hh b/src/include/dso-deployer.hh | |
| deleted file mode 100644 | |
| index a5b4751..0000000 | |
| --- a/src/include/dso-deployer.hh | |
| +++ /dev/null | |
| @@ -1,96 +0,0 @@ | |
| -/* Copyright 2008 (C) Nicira, Inc. | |
| - * | |
| - * This file is part of NOX. | |
| - * | |
| - * NOX is free software: you can redistribute it and/or modify | |
| - * it under the terms of the GNU General Public License as published by | |
| - * the Free Software Foundation, either version 3 of the License, or | |
| - * (at your option) any later version. | |
| - * | |
| - * NOX is distributed in the hope that it will be useful, | |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| - * GNU General Public License for more details. | |
| - * | |
| - * You should have received a copy of the GNU General Public License | |
| - * along with NOX. If not, see <http://www.gnu.org/licenses/>. | |
| - */ | |
| -#ifndef DSO_DEPLOYER_HH | |
| -#define DSO_DEPLOYER_HH 1 | |
| - | |
| -#include "config.h" | |
| - | |
| -#include <ltdl.h> | |
| - | |
| -#include <list> | |
| -#include <vector> | |
| - | |
| -#include "component.hh" | |
| -#include "deployer.hh" | |
| -#include "kernel.hh" | |
| - | |
| -namespace vigil | |
| -{ | |
| - | |
| -/* | |
| - * A dynamic shared object deployer. | |
| - * | |
| - * While constructed, the DSO deployer scans the directory structure | |
| - * for any components being implemented as DSOs. | |
| - */ | |
| -class DSO_deployer | |
| - : public Component, public Deployer | |
| -{ | |
| -public: | |
| - virtual ~DSO_deployer(); | |
| - | |
| - typedef std::list<std::string> Path_list; | |
| - | |
| - static Component* instantiate(const Component_context*, | |
| - const Path_list& lib_search_paths); | |
| - | |
| - void configure(); | |
| - void install(); | |
| - | |
| - /* Return the DSO search paths */ | |
| - Path_list get_search_paths() const; | |
| - | |
| -private: | |
| - DSO_deployer(const Component_context* ctxt, | |
| - const Path_list& lib_search_paths); | |
| - | |
| - const Path_list lib_dirs; | |
| -}; | |
| - | |
| -class DSO_component_context | |
| - : public Component_context | |
| -{ | |
| -public: | |
| - DSO_component_context(const Component_name& name, | |
| - const std::string& config_path); | |
| - | |
| -private: | |
| - /* Actions implementing state transitions */ | |
| - void describe(); | |
| - void load(); | |
| - void instantiate_factory(); | |
| - void instantiate(); | |
| - void configure(); | |
| - void install(); | |
| - | |
| - typedef Component_factory* component_factory_function(); | |
| - component_factory_function* find_factory_function(const char*) const; | |
| - | |
| - /* Library name */ | |
| - std::string library; | |
| - | |
| - /* Handle to DSO */ | |
| - ::lt_dlhandle handle; | |
| - | |
| - /* Factory instance */ | |
| - Component_factory* factory; | |
| -}; | |
| - | |
| -} | |
| - | |
| -#endif | |
| diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am | |
| index 1a68526..69bce52 100644 | |
| --- a/src/lib/Makefile.am | |
| +++ b/src/lib/Makefile.am | |
| @@ -4,14 +4,14 @@ CONFIGURE_DEPENCIES = $(srcdir)/Makefile.am | |
| NOXCORE_LIB_VERSION = 1:0:0 | |
| -lib_LTLIBRARIES = libnoxcore.la | |
| +lib_LIBRARIES = libnoxcore.a | |
| EXTRA_DIST = \ | |
| dh1024.pem \ | |
| dh2048.pem \ | |
| dh4096.pem | |
| -libnoxcore_la_SOURCES = \ | |
| +libnoxcore_a_SOURCES = \ | |
| command-line.cc \ | |
| connection.cc \ | |
| dhparams.h \ | |
| @@ -24,19 +24,19 @@ libnoxcore_la_SOURCES = \ | |
| timeval.cc \ | |
| vlog.cc | |
| -nodist_libnoxcore_la_SOURCES = \ | |
| +nodist_libnoxcore_a_SOURCES = \ | |
| dhparams.c | |
| -libnoxcore_la_LIBADD = \ | |
| - $(BOOST_FILESYSTEM_LIB) \ | |
| - $(BOOST_SYSTEM_LIB) \ | |
| - $(BOOST_SERIALIZATION_LIB) \ | |
| - $(BOOST_THREAD_LIB) \ | |
| - $(BOOST_UNIT_TEST_FRAMEWORK_LIB) \ | |
| - $(OPENSSL_LIBS) | |
| +#libnoxcore_a_LIBADD = \ | |
| +# $(BOOST_FILESYSTEM_LIB) \ | |
| +# $(BOOST_SYSTEM_LIB) \ | |
| +# $(BOOST_SERIALIZATION_LIB) \ | |
| +# $(BOOST_THREAD_LIB) \ | |
| +# $(BOOST_UNIT_TEST_FRAMEWORK_LIB) \ | |
| +# $(OPENSSL_LIBS) | |
| -libnoxcore_la_LDFLAGS = \ | |
| - $(AM_LDFLAGS) -version-info $(NOXCORE_LIB_VERSION) | |
| +#libnoxcore_a_LDFLAGS = \ | |
| +#` $(AM_LDFLAGS) -version-info $(NOXCORE_LIB_VERSION) | |
| dhparams.c: dh1024.pem dh2048.pem dh4096.pem | |
| (echo '#include "dhparams.h"' && \ | |
| @@ -47,7 +47,7 @@ dhparams.c: dh1024.pem dh2048.pem dh4096.pem | |
| mv dhparams.c.tmp dhparams.c | |
| install-exec-hook: \ | |
| - @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ | |
| + @list='$(lib_LIBRARIES)'; for p in $$list; do \ | |
| if test -f $$p; then \ | |
| f=$(am__strip_dir) \ | |
| echo $(DESTDIR)$(libdir)/$$f \ | |
| diff --git a/src/lib/connection.cc b/src/lib/connection.cc | |
| index 2135264..c88d9c2 100644 | |
| --- a/src/lib/connection.cc | |
| +++ b/src/lib/connection.cc | |
| @@ -106,8 +106,10 @@ Stream_connection<Async_stream>::Stream_connection( | |
| : Connection(), stream(stream), strand(stream->get_io_service()), | |
| tx_bytes(0), rx_bytes(0) | |
| { | |
| + /* | |
| ba::ip::tcp::socket::non_blocking_io non_blocking_io(true); | |
| stream->lowest_layer().io_control(non_blocking_io); | |
| + */ | |
| } | |
| /* Close the stream associated with this connection */ | |
| diff --git a/src/nox_main.cc b/src/nox_main.cc | |
| index dc32f4e..6562c1d 100644 | |
| --- a/src/nox_main.cc | |
| +++ b/src/nox_main.cc | |
| @@ -77,7 +77,10 @@ | |
| #include "command-line.hh" | |
| #include "component.hh" | |
| #include "connection-manager.hh" | |
| -#include "dso-deployer.hh" | |
| +#include "coreapps/openflow/openflow-manager.hh" | |
| +#include "coreapps/switch/switch.hh" | |
| + | |
| +//#include "dso-deployer.hh" | |
| #include "event.hh" | |
| #include "fault.hh" | |
| #include "kernel.hh" | |
| @@ -92,13 +95,11 @@ | |
| #endif | |
| using namespace vigil; | |
| +using namespace apps; | |
| using namespace std; | |
| // TODO: MOVE SOME FUNCTIONALITY TO KERNEL | |
| -namespace | |
| -{ | |
| - | |
| Vlog_module lg("main"); | |
| typedef std::string Application_name; | |
| @@ -255,7 +256,6 @@ void init_log() | |
| #endif | |
| } | |
| -} // unnamed namespace | |
| Disposition remove_pid_file(const char* pid_file, const Event&) | |
| { | |
| @@ -264,8 +264,6 @@ Disposition remove_pid_file(const char* pid_file, const Event&) | |
| return CONTINUE; | |
| } | |
| -static void finish_booting(Kernel*, const Application_list&); | |
| - | |
| // TODO: fix shutdown handling | |
| boost::function<void()> post_shutdown; | |
| void shutdown(int param) | |
| @@ -274,6 +272,47 @@ void shutdown(int param) | |
| post_shutdown(); | |
| } | |
| +static void finish_booting(Kernel* kernel, const Application_list& applications) | |
| +{ | |
| + string fatal_error; | |
| + | |
| + try | |
| + { | |
| + /* Boot the components defined on the command-line */ | |
| + BOOST_FOREACH(Application_param app, applications) | |
| + { | |
| + Application_name& name = app.first; | |
| + if (!kernel->get(name)) | |
| + { | |
| + kernel->install(name, INSTALLED); | |
| + } | |
| + } | |
| + } | |
| + catch (const runtime_error& e) | |
| + { | |
| + fatal_error = e.what(); | |
| + } | |
| + | |
| + /* Report the installation results. */ | |
| + lg.dbg("Application installation report:"); | |
| + BOOST_FOREACH(Component_context* ctxt, kernel->get_all()) | |
| + { | |
| + lg.dbg("%s:\n%s\n", ctxt->get_name().c_str(), | |
| + ctxt->get_status().c_str()); | |
| + } | |
| + | |
| + /* Check all requested applications have booted. */ | |
| + if (fatal_error != "") | |
| + { | |
| + lg.err("%s", fatal_error.c_str()); | |
| + exit(EXIT_FAILURE); | |
| + } | |
| + | |
| + // TODO: FIX THIS | |
| + //nox::post_event(new Bootstrap_complete_event()); | |
| + lg.info("nox bootstrap complete"); | |
| +} | |
| + | |
| int main(int argc, char *argv[]) | |
| { | |
| namespace fs = boost::filesystem; | |
| @@ -513,15 +552,32 @@ int main(int argc, char *argv[]) | |
| kernel->install(event_dispatcher_context, INSTALLED); | |
| + Component_context* openflow_manager_context = | |
| + new Static_component_context( | |
| + boost::bind(&Openflow_manager::instantiate, _1), | |
| + typeid(Openflow_manager).name(), | |
| + "openflow-manager", | |
| + platform_config_path); | |
| + kernel->install(openflow_manager_context, INSTALLED); | |
| + | |
| + Component_context* switch_context = | |
| + new Static_component_context( | |
| + boost::bind(&Switch::instantiate, _1), | |
| + typeid(Switch).name(), | |
| + "switch", | |
| + platform_config_path); | |
| + kernel->install(switch_context, INSTALLED); | |
| + | |
| /* Install the deployer responsible for DSOs. */ | |
| + /* | |
| Component_context* dso_deployer_context = | |
| new Static_component_context( | |
| boost::bind(&DSO_deployer::instantiate, _1, lib_dirs), | |
| typeid(DSO_deployer).name(), | |
| "dso-deployer", | |
| platform_config_path); | |
| + */ | |
| - kernel->install(dso_deployer_context, INSTALLED); | |
| /* Install the connection manager. */ | |
| Component_context* connection_manager_context = | |
| @@ -570,44 +626,3 @@ int main(int argc, char *argv[]) | |
| return 0; | |
| } | |
| - | |
| -static void finish_booting(Kernel* kernel, const Application_list& applications) | |
| -{ | |
| - string fatal_error; | |
| - | |
| - try | |
| - { | |
| - /* Boot the components defined on the command-line */ | |
| - BOOST_FOREACH(Application_param app, applications) | |
| - { | |
| - Application_name& name = app.first; | |
| - if (!kernel->get(name)) | |
| - { | |
| - kernel->install(name, INSTALLED); | |
| - } | |
| - } | |
| - } | |
| - catch (const runtime_error& e) | |
| - { | |
| - fatal_error = e.what(); | |
| - } | |
| - | |
| - /* Report the installation results. */ | |
| - lg.dbg("Application installation report:"); | |
| - BOOST_FOREACH(Component_context* ctxt, kernel->get_all()) | |
| - { | |
| - lg.dbg("%s:\n%s\n", ctxt->get_name().c_str(), | |
| - ctxt->get_status().c_str()); | |
| - } | |
| - | |
| - /* Check all requested applications have booted. */ | |
| - if (fatal_error != "") | |
| - { | |
| - lg.err("%s", fatal_error.c_str()); | |
| - exit(EXIT_FAILURE); | |
| - } | |
| - | |
| - // TODO: FIX THIS | |
| - //nox::post_event(new Bootstrap_complete_event()); | |
| - lg.info("nox bootstrap complete"); | |
| -} | |
| diff --git a/src/coreapps/switch/switch.hh b/src/coreapps/switch/switch.hh | |
| new file mode 100644 | |
| index 0000000..df9983b | |
| --- /dev/null | |
| +++ b/src/coreapps/switch/switch.hh | |
| @@ -0,0 +1,79 @@ | |
| +#ifndef SWITCH_HH | |
| +#define SWITCH_HH | |
| + | |
| +#include <cstring> | |
| +#include <netinet/in.h> | |
| +#include <stdexcept> | |
| +#include <stdint.h> | |
| +#include <string> | |
| + | |
| +#include <boost/bind.hpp> | |
| +#include <boost/foreach.hpp> | |
| + | |
| +//#include <tbb/concurrent_hash_map.h> | |
| + | |
| +#include "assert.hh" | |
| +#include "component.hh" | |
| +#include "vlog.hh" | |
| + | |
| +#include "netinet++/datapathid.hh" | |
| +#include "netinet++/ethernetaddr.hh" | |
| +#include "netinet++/ethernet.hh" | |
| + | |
| +#include "openflow/openflow-event.hh" | |
| +#include "openflow/openflow-datapath-join-event.hh" | |
| +#include "openflow/openflow-datapath-leave-event.hh" | |
| + | |
| +using namespace vigil; | |
| +using namespace openflow; | |
| + | |
| +namespace apps | |
| +{ | |
| + | |
| + | |
| +class Switch | |
| + : public Component | |
| +{ | |
| +public: | |
| + | |
| + static Component* instantiate(const Component_context*); | |
| + void configure(); | |
| + | |
| + void install() {} | |
| + | |
| + Disposition handle_datapath_join(const Event&); | |
| + Disposition handle_datapath_leave(const Event&); | |
| + Disposition handle_packet_in(const Event&); | |
| + | |
| +private: | |
| + Switch(const Component_context* c) | |
| + : Component(c) | |
| + { | |
| + setup_flows = true; // default value | |
| + } | |
| + | |
| + /* | |
| + struct datapath_hasher { | |
| + static size_t hash(const datapathid& o) { | |
| + return boost::hash_value(o.as_host()); | |
| + } | |
| + static bool equal(const datapathid& o1, const datapathid& o2) | |
| + { | |
| + return o1 == o2; | |
| + } | |
| + }; | |
| + */ | |
| + typedef boost::unordered_map<ethernetaddr, int> mac_table; | |
| + //typedef tbb::concurrent_hash_map<datapathid, mac_table, datapath_hasher> mac_table_map; | |
| + | |
| + typedef boost::unordered_map<datapathid, mac_table> mac_table_map; | |
| + | |
| + mac_table_map mac_tables; | |
| + | |
| + /* Set up a flow when we know the destination of a packet? This should | |
| + * ordinarily be true; it is only usefully false for debugging purposes. */ | |
| + bool setup_flows; | |
| +}; | |
| +} | |
| + | |
| +#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment