Hi,
I added vendor_msg event in the nox core (attaching the patch, but not
sure if its strictly required or if there is any work around). With
that patch applied to nox 0.5.0, I wrote following callback in the
pyswitch:
<code>
def vendor_msg_callback(*params):
print "In here for vendor message"
if params:
for para in params:
print "(%s)" % (para)
return CONTINUE
</code>
I am sending some vendor specific events from Openflow Click switch. I
get following output at the Nox console:
<output>
00035|nox|DBG:Registering switch with DPID = f5de7bce86
00036|nox.coreapps.examples.pyswitch|INFO:Switch f5de7bce86 has joined
the network
00037|openflow-event|DBG:received vendor event from 00f5de7bce86
In here for vendor message
(<nox.coreapps.pyrt.pycomponent.pyevent; proxy of <Swig Object of type
'pyevent *' at 0xb5f00578> >)
00038|openflow-event|DBG:received echo-request event from 00f5de7bce86 (len:0)
</output>
It seems that its only sending one parameter which is swig proxy
object. But I think I have written conversion function properly in
pyrt.cc. Any ideas how to fix it?
-Yogesh
On Mon, Jan 25, 2010 at 5:18 AM, Yogesh Mundada <[email protected]> wrote:
> Hi KK,
>
> Is there a way to register for vendor specific msg events in python
> applications in Nox?
>
> I see from
> "http://noxrepo.org/pipermail/nox-dev_noxrepo.org/2008-December/000484.html"
> that you had somehow enabled Openflow_msg_event. I am assuming that
> its like a generic event thrown for any un-handled ofp_type (Is that
> right?). However, when I saw code for openflow-event.cc, there is no
> handle_openflow_msg() being called. Also in core.py, there is no
> register_for_openflow_msg(). There is a magic etc/nox.xml file with
> couple of events and filters mentioned in it. Can you shed some light
> on how it is to be used?
>
> My Nox controller version is 0.5.0 and OFClick switch is 0.8.9~2.
>
> If I have to add this event myself, I think I would have to make
> following changes at the very least:
> 1. Detect the packet type as OpenFlow Vendor header and write a
> handler in openflow-event.cc
> 2. Define a Vendor_msg_event class in include/vendor-msg.hh
> 3. Register in event-dispatcher-component.cc
> 4. Write conversion functions in pyrt.cc and interface information in event.i
> 5. Write register_for_vendor_msg_event() in core.py
>
> Would that be all?
>
> -Yogesh
>
diff -Naur src/builtin/event-dispatcher-component.cc /data/noxcore_new/nox-0.5.0~full~beta/src/builtin/event-dispatcher-component.cc
--- src/builtin/event-dispatcher-component.cc 2009-02-03 12:16:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/builtin/event-dispatcher-component.cc 2010-01-25 05:19:42.000000000 -0700
@@ -22,6 +22,7 @@
#include "error-event.hh"
#include "bootstrap-complete.hh"
#include "flow-expired.hh"
+#include "vendor-msg.hh"
#include "flow-mod-event.hh"
#include "packet-in.hh"
#include "port-status.hh"
@@ -91,6 +92,7 @@
register_event<Flow_expired_event>();
register_event<Flow_mod_event>();
register_event<Packet_in_event>();
+ register_event<Vendor_msg_event>();
register_event<Port_status_event>();
register_event<Shutdown_event>();
register_event<Bootstrap_complete_event>();
diff -Naur src/include/Makefile.am /data/noxcore_new/nox-0.5.0~full~beta/src/include/Makefile.am
--- src/include/Makefile.am 2009-02-03 12:16:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/include/Makefile.am 2010-01-25 05:03:46.000000000 -0700
@@ -86,6 +86,7 @@
timer-dispatcher.hh \
timeval.hh \
type-props.h \
+vendor-msg.hh \
vlog-socket.hh \
vlog.hh \
xml-util.hh \
diff -Naur src/include/Makefile.in /data/noxcore_new/nox-0.5.0~full~beta/src/include/Makefile.in
--- src/include/Makefile.in 2009-02-23 14:28:19.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/include/Makefile.in 2010-01-25 05:25:34.000000000 -0700
@@ -306,6 +306,7 @@
timer-dispatcher.hh \
timeval.hh \
type-props.h \
+vendor-msg.hh \
vlog-socket.hh \
vlog.hh \
xml-util.hh \
diff -Naur src/include/vendor-msg.hh /data/noxcore_new/nox-0.5.0~full~beta/src/include/vendor-msg.hh
--- src/include/vendor-msg.hh 1969-12-31 17:00:00.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/include/vendor-msg.hh 2010-01-25 05:12:01.000000000 -0700
@@ -0,0 +1,59 @@
+#ifndef VENDOR_MSG_HH
+#define VENDOR_MSG_HH 1
+
+#include <memory>
+#include <iostream>
+#include <boost/shared_ptr.hpp>
+#include <arpa/inet.h>
+#include "openflow/openflow.h"
+#include "buffer.hh"
+#include "event.hh"
+#include "netinet++/datapathid.hh"
+#include "ofp-msg-event.hh"
+#include "openflow.hh"
+
+namespace vigil {
+
+struct Vendor_msg_event
+ : public Event,
+ public Ofp_msg_event
+{
+ Vendor_msg_event(datapathid datapath_id_, uint32_t vendor_,
+ std::auto_ptr<Buffer> buf_, size_t total_len_)
+ : Event(static_get_name()), Ofp_msg_event((ofp_header*) NULL, buf_),
+ datapath_id(datapath_id_), vendor(vendor_), total_len(total_len_)
+ {}
+
+ Vendor_msg_event(datapathid datapath_id_, uint32_t vendor_,
+ boost::shared_ptr<Buffer> buf_, size_t total_len_)
+ : Event(static_get_name()), Ofp_msg_event((ofp_header*) NULL, buf_),
+ datapath_id(datapath_id_), vendor(vendor_), total_len(total_len_)
+ {}
+
+ Vendor_msg_event(datapathid datapath_id_,
+ const ofp_vendor_header *ovh, std::auto_ptr<Buffer> buf_)
+ : Event(static_get_name()), Ofp_msg_event(&ovh->header, buf_),
+ datapath_id(datapath_id_),
+ vendor(ntohs(ovh->vendor)),
+ total_len(ntohs(ovh->header.length)-sizeof(struct ofp_header)-4)
+ {}
+
+ virtual ~Vendor_msg_event() { }
+
+ const boost::shared_ptr<Buffer>& get_buffer() const { return buf; }
+
+ static const Event_name static_get_name() {
+ return "Vendor_msg_event";
+ }
+
+ datapathid datapath_id;
+ uint32_t vendor;
+ size_t total_len;
+
+ Vendor_msg_event(const Vendor_msg_event&);
+ Vendor_msg_event& operator=(const Vendor_msg_event&);
+};
+
+} // namespace vigil
+
+#endif /* packet-in.hh */
diff -Naur src/lib/openflow-event.cc /data/noxcore_new/nox-0.5.0~full~beta/src/lib/openflow-event.cc
--- src/lib/openflow-event.cc 2009-02-03 12:16:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/lib/openflow-event.cc 2010-01-25 05:16:52.000000000 -0700
@@ -31,6 +31,7 @@
#include "buffer.hh"
#include "datapath.hh"
#include "packet-in.hh"
+#include "vendor-msg.hh"
#include "port-status.hh"
#include "datapath-join.hh"
#include "echo-request.hh"
@@ -40,6 +41,7 @@
#include "table-stats-in.hh"
#include "port-stats-in.hh"
#include "error-event.hh"
+//#include "openflow-msg-in.hh"
#include "flow-expired.hh"
#include "openflow.hh"
#include "vlog.hh"
@@ -64,6 +66,15 @@
}
Event*
+handle_vendor_msg(datapathid datapath_id,
+ const ofp_vendor_header *ovh, std::auto_ptr<Buffer> buf)
+{
+ lg.dbg("received vendor event from %s",
+ datapath_id.string().c_str());
+ return new Vendor_msg_event(datapath_id, ovh, buf);
+}
+
+Event*
handle_flow_expired(datapathid datapath_id,
const ofp_flow_expired *ofe, std::auto_ptr<Buffer> buf)
{
@@ -150,6 +161,12 @@
len -= sizeof(ofp_stats_reply);
ofp_port_stats* ops = (struct ofp_port_stats*)osr->body;
for (int i = 0; i < len / sizeof(ofp_port_stats); ++i){
+ // dgu: hack to get xid information up to the python component
+ if(i == 0) {
+ ops->rx_crc_err = htonl(osr->header.xid);
+ ops->rx_crc_err = ops->rx_crc_err << 32;
+ }
+
psie->add_port(ops);
ops++;
}
@@ -270,7 +287,6 @@
return NULL;
}
-
switch (oh->type) {
case OFPT_PACKET_IN:
return handle_packet(handle_packet_in, datapath_id, oh, p);
@@ -287,6 +303,8 @@
case OFPT_ECHO_REPLY:
return NULL;
// TODO OFPT_CLOSE
+ case OFPT_VENDOR:
+ return handle_packet(handle_vendor_msg, datapath_id, oh, p);
case OFPT_ERROR:
return handle_packet(handle_error, datapath_id, oh, p);
default:
diff -Naur src/nox/coreapps/examples/pyswitch.py /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/examples/pyswitch.py
--- src/nox/coreapps/examples/pyswitch.py 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/examples/pyswitch.py 2010-01-25 06:10:01.000000000 -0700
@@ -148,6 +148,14 @@
return CONTINUE
+def vendor_msg_callback(*params):
+ print "In here for vendor message"
+ if params:
+ for para in params:
+ print "(%s)" % (para)
+ #print "dpid: %s" % (dpid)
+ return CONTINUE
+
class pyswitch(Component):
def __init__(self, ctxt):
@@ -161,6 +169,7 @@
inst.register_for_packet_in(packet_in_callback)
inst.register_for_datapath_leave(datapath_leave_callback)
inst.register_for_datapath_join(datapath_join_callback)
+ inst.register_for_vendor_msg(vendor_msg_callback)
inst.post_callback(1, timer_callback)
def getInterface(self):
diff -Naur src/nox/coreapps/pyrt/event.i /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/pyrt/event.i
--- src/nox/coreapps/pyrt/event.i 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/pyrt/event.i 2010-01-25 04:51:15.000000000 -0700
@@ -102,6 +102,15 @@
Packet_in_event();
};
+struct Vendor_msg_event
+ : public Event
+{
+ static const std::string static_get_name();
+
+private:
+ Vendor_msg_event();
+};
+
struct Echo_request_event
: public Event
{
diff -Naur src/nox/coreapps/pyrt/pycontext.cc /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/pyrt/pycontext.cc
--- src/nox/coreapps/pyrt/pycontext.cc 2009-02-12 12:16:34.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/pyrt/pycontext.cc 2010-01-25 05:27:24.000000000 -0700
@@ -44,6 +44,7 @@
#include "flow-expired.hh"
#include "flow-mod-event.hh"
#include "packet-in.hh"
+#include "vendor-msg.hh"
#include "port-status.hh"
#include "pycomponent.hh"
#include "pyevent.hh"
diff -Naur src/nox/coreapps/pyrt/pyrt.cc /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/pyrt/pyrt.cc
--- src/nox/coreapps/pyrt/pyrt.cc 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/coreapps/pyrt/pyrt.cc 2010-01-25 05:23:26.000000000 -0700
@@ -38,6 +38,7 @@
#include "flow-expired.hh"
#include "flow-mod-event.hh"
#include "packet-in.hh"
+#include "vendor-msg.hh"
#include "port-status.hh"
#include "pyevent.hh"
#include "pyglue.hh"
@@ -286,6 +287,19 @@
((Event*)swigo->ptr)->operator=(e);
}
+static void convert_vendor_msg(const Event& e, PyObject* proxy) {
+ const Vendor_msg_event& pie = dynamic_cast<const Vendor_msg_event&>(e);
+
+ pyglue_setattr_string(proxy, "vendor", to_python(pie.vendor));
+ pyglue_setattr_string(proxy, "total_len", to_python(pie.total_len));
+ pyglue_setattr_string(proxy, "datapath_id", to_python(pie.datapath_id));
+ pyglue_setattr_string(proxy, "buf", to_python<boost::shared_ptr<Buffer> >
+ (pie.get_buffer()));
+
+ PySwigObject* swigo = SWIG_Python_GetSwigThis(proxy);
+ ((Event*)swigo->ptr)->operator=(e);
+}
+
static void convert_port_status(const Event& e, PyObject* proxy) {
const Port_status_event& pse = dynamic_cast<const Port_status_event&>(e);
@@ -316,12 +330,9 @@
// anyway. The easiest way to deal with it is to save and restore
// the SIGINT handler around Py_Initialize() and the initial
// import of the signal module, so that's what we do.
- // Extra Note: We also store and replace the handlers for TERM and HUP
- struct sigaction sa_term,sa_int,sa_hup;
- sigaction(SIGTERM, NULL, &sa_term);
- sigaction(SIGINT, NULL, &sa_int);
- sigaction(SIGHUP, NULL, &sa_hup);
-
+ struct sigaction sa;
+ sigaction(SIGINT, NULL, &sa);
+
// Initialize Python
Py_Initialize();
PySys_SetArgv(c->get_kernel()->argc, c->get_kernel()->argv);
@@ -346,9 +357,7 @@
// imports reactor will set the default reactor in stone.
initialize_oxide_reactor();
- sigaction(SIGTERM, &sa_term, NULL);
- sigaction(SIGINT, &sa_int, NULL);
- sigaction(SIGHUP, &sa_hup, NULL);
+ sigaction(SIGINT, &sa, NULL);
// Fetch the library paths from the core DSO deployer
DSO_deployer* dso_deployer =
@@ -413,6 +422,8 @@
&convert_flow_mod);
register_event_converter(Packet_in_event::static_get_name(),
&convert_packet_in);
+ register_event_converter(Vendor_msg_event::static_get_name(),
+ &convert_vendor_msg);
register_event_converter(Port_status_event::static_get_name(),
&convert_port_status);
register_event_converter(Shutdown_event::static_get_name(),
diff -Naur src/nox/lib/core.py /data/noxcore_new/nox-0.5.0~full~beta/src/nox/lib/core.py
--- src/nox/lib/core.py 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/lib/core.py 2010-01-25 05:55:19.000000000 -0700
@@ -398,6 +398,10 @@
self.register_handler(Flow_expired_event.static_get_name(),
handler)
+ def register_for_vendor_msg(self, handler):
+ self.register_handler(Vendor_msg_event.static_get_name(),
+ handler)
+
def register_for_flow_mod(self, handler):
self.register_handler(Flow_mod_event.static_get_name(),
handler)
diff -Naur src/nox/netapps/authenticator/flow_in.hh /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/authenticator/flow_in.hh
--- src/nox/netapps/authenticator/flow_in.hh 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/authenticator/flow_in.hh 2010-01-25 05:36:41.000000000 -0700
@@ -28,6 +28,7 @@
#include "flow.hh"
#include "hash_set.hh"
#include "packet-in.hh"
+#include "vendor-msg.hh"
#include "pyrt/pyglue.hh"
namespace vigil {
diff -Naur src/nox/netapps/directory/dirmanager.i /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/directory/dirmanager.i
--- src/nox/netapps/directory/dirmanager.i 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/directory/dirmanager.i 2010-01-25 05:47:19.000000000 -0700
@@ -27,6 +27,7 @@
#include "flow-expired.hh"
#include "flow-mod-event.hh"
#include "packet-in.hh"
+#include "vendor-msg.hh"
#include "port-stats-in.hh"
#include "port-status.hh"
#include "table-stats-in.hh"
diff -Naur src/nox/netapps/directory/netinfo_mod_event.i /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/directory/netinfo_mod_event.i
--- src/nox/netapps/directory/netinfo_mod_event.i 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/directory/netinfo_mod_event.i 2010-01-25 05:46:32.000000000 -0700
@@ -27,6 +27,7 @@
#include "table-stats-in.hh"
#include "port-stats-in.hh"
#include "packet-in.hh"
+#include "vendor-msg.hh"
#include "port-status.hh"
#include "echo-request.hh"
#include "pyrt/pycontext.hh"
diff -Naur src/nox/netapps/discovery/link.i /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/discovery/link.i
--- src/nox/netapps/discovery/link.i 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/discovery/link.i 2010-01-25 05:44:54.000000000 -0700
@@ -27,6 +27,7 @@
#include "table-stats-in.hh"
#include "port-stats-in.hh"
#include "packet-in.hh"
+#include "vendor-msg.hh"
#include "port-status.hh"
#include "echo-request.hh"
#include "pyrt/pycontext.hh"
diff -Naur src/nox/netapps/tests/tests.cc /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/tests/tests.cc
--- src/nox/netapps/tests/tests.cc 2009-02-11 17:58:25.000000000 -0700
+++ /data/noxcore_new/nox-0.5.0~full~beta/src/nox/netapps/tests/tests.cc 2010-01-25 05:51:27.000000000 -0700
@@ -107,7 +107,7 @@
void testPython() {
// Construct a twisted.trial.reporter.TestResult object
- PyObject* n = PyString_FromString("twisted/trial/reporter");
+ PyObject* n = PyString_FromString("twisted.trial.reporter");
PyObject* m = PyImport_Import(n);
if (PyErr_Occurred()) {
PyErr_Print();
_______________________________________________
nox-dev mailing list
[email protected]
http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org