commit 59a6d0615fbc1ef7676dc4050852ab43097404b0
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Aug 16 09:54:41 2013 +0200
NetTestSlave: listen for netlink notifications
The slave server now listens to NETLINK_ROUTE notifications. At the
moment only RTM_NEWLINK messages are interesting to us, so we construct
update messages from these and send them to the controller.
The update messages contain the name of the interface, it's hw address,
and the index under which it is recognized in the kernel. The index is
useless right now but it will be useful later when we will have an
internal interface database.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Slave/NetTestSlave.py | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 0f17839..641b83b 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -38,6 +38,26 @@ from lnst.Common.ConnectionHandler import ConnectionHandler
from lnst.Common.Config import lnst_config
from lnst.Common.NetTestCommand import NetTestCommandConfig
+#TODO this is temporary, until python-pyroute2 package is updated
+from pyroute2.netlink import NetlinkSocket
+from pyroute2.netlink.generic import NETLINK_ROUTE
+
+RTNLGRP_LINK = 0x1
+RTNLGRP_NEIGH = 0x4
+RTNLGRP_TC = 0x8
+RTNLGRP_IPV4_IFADDR = 0x10
+RTNLGRP_IPV4_ROUTE = 0x40
+RTNLGRP_IPV6_IFADDR = 0x100
+RTNLGRP_IPV6_ROUTE = 0x400
+
+RTNL_GROUPS = RTNLGRP_IPV4_IFADDR |\
+ RTNLGRP_IPV6_IFADDR |\
+ RTNLGRP_IPV4_ROUTE |\
+ RTNLGRP_IPV6_ROUTE |\
+ RTNLGRP_NEIGH |\
+ RTNLGRP_LINK |\
+ RTNLGRP_TC
+
DefaultRPCPort = 9999
class SlaveMethods:
@@ -433,6 +453,10 @@ class NetTestSlave:
self._start = True
+ self._nl_socket = NetlinkSocket(family=NETLINK_ROUTE)
+ self._nl_socket.bind(RTNL_GROUPS)
+ self._server_handler.add_connection('netlink', self._nl_socket)
+
def run(self):
while not self._finished:
if self._server_handler.get_ctl_sock() == None:
@@ -511,6 +535,19 @@ class NetTestSlave:
self._cmd_context.del_cmd(cmd)
else:
cmd.set_result(msg["result"])
+ elif msg["type"] == "netlink":
+ for sub_msg in msg["data"]:
+ if sub_msg["event"] == "RTM_NEWLINK":
+ response = dict()
+ response["type"] = "if_update"
+ response["if_index"] = sub_msg["index"]
+ msg_attrs = sub_msg["attrs"]
+ for name, value in msg_attrs:
+ if name == "IFLA_IFNAME":
+ response["devname"] = value
+ elif name == "IFLA_ADDRESS":
+ response["hwaddr"] = value
+ self._server_handler.send_data_to_ctl(response)
else:
raise Exception("Recieved unknown command")
Show replies by date