91 | | == 3.1 Adding flags. == |
92 | | The `configure` function allows you to define options for your application. When starting nox_core, flags can be specified by the application name, followed by an '=', then your flag(s): |
| 91 | == 3.1 The configure function. == |
| 92 | The `configure` function allows you to register the events that the module will respond to via the `Disposition` type function (more detail later on regarding this), and to define options for your application. |
| 93 | |
| 94 | === 3.1.1. starting modules with flags === |
| 95 | When starting nox_core, flags can be specified by the application name, followed by an '=', then your flag(s): |
| 101 | === 3.1.2. registering events. === |
| 102 | This is done with the `register_handler` which takes your event's name and allows you to specify a NOX event to bind to it: |
| 103 | |
| 104 | {{{ |
| 105 | register_handler<Flow_in_event> |
| 106 | (boost::bind(&SPRouting::handle_flow_in, this, _1)); |
| 107 | }}} |
| 108 | Here, a Flow_in_event (defined in NOX libraries) is taken as an argument to the module specific Disposition type function `handle_flow_in`. |
| 109 | |
| 110 | This snippet is taken from the built-in routing module (netapps/routing/sprouting.cc, .hh) which makes an OF switch behave like a router. The sprouting module is fairly complex and can be used to see how a module is built; we'll be using pieces of this module (along with others where specified) throughout this page. |
| 111 | |
| 112 | === 3.1.3. defining flags/options. === |
| 113 | It seems customary to define and check for flags within configure function, but this doesn't have to be the case. For example, in sprouting, there is a separate function called `validate_args`. |
| 115 | A more "traditional" way of doing this is through the Configuration object (found in nox/src/nox/component.hh): |
| 116 | {{{ |
| 117 | class Configuration { |
| 118 | public: |
| 119 | virtual ~Configuration(); |
| 120 | |
| 121 | /* Retrieve a value of an XML configuration key. */ |
| 122 | virtual const std::string get(const std::string& key) const = 0; |
| 123 | |
| 124 | /* Return true if the XML key exists. */ |
| 125 | virtual const bool has(const std::string& key) const = 0; |
| 126 | |
| 127 | /* Return all XML keys. */ |
| 128 | virtual const std::list<std::string> keys() const = 0; |
| 129 | |
| 130 | /* Return all command line arguments of the component. */ |
| 131 | virtual const Component_argument_list get_arguments() const = 0; |
| 132 | |
| 133 | /* Return list of arguments. */ |
| 134 | virtual const hash_map<std::string, std::string> |
| 135 | get_arguments_list(char d1 = ',', char d2 = '=') const = 0; |
| 136 | }; |
| 137 | }}} |
| 138 | |
| 139 | This class allows you to input flags as described earlier in 3.1.1. Actually using the class involves something like this (from switch.cc). |
| 140 | {{{ |
| 141 | Switch::configure(const Configuration* conf) { |
| 142 | ... |
| 143 | BOOST_FOREACH (const std::string& arg, conf->get_arguments()) { |
| 144 | if (arg == "noflow") { |
| 145 | setup_flows = false; |
| 146 | } else { |
| 147 | VLOG_WARN(log, "argument \"%s\" not supported", arg.c_str()); |
| 148 | } |
| 149 | } |
| 150 | ... |
| 151 | }}} |
| 152 | |
| 153 | == 3.2. Event triggers == |
| 154 | === 3.2.1 The Disposition type === |
| 155 | |