Created
November 2, 2013 02:39
-
-
Save thehajime/7274860 to your computer and use it in GitHub Desktop.
mswim 2013 demonstration: patch for ns-3-dev (60b0d4d40fb9)
This file contains 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
# HG changeset patch | |
# Parent 99bf9f9ef69a38a828d578ccdc17ffad5e493103 | |
diff -r 99bf9f9ef69a src/lte/model/lte-enb-net-device.cc | |
--- a/src/lte/model/lte-enb-net-device.cc Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/lte/model/lte-enb-net-device.cc Thu Oct 31 19:54:48 2013 +0900 | |
@@ -262,6 +262,8 @@ | |
{ | |
NS_LOG_FUNCTION (this << packet << dest << protocolNumber); | |
NS_ASSERT_MSG (protocolNumber == Ipv4L3Protocol::PROT_NUMBER, "unsupported protocol " << protocolNumber << ", only IPv4 is supported"); | |
+ Mac48Address to = Mac48Address::ConvertFrom (dest); | |
+ m_traceTx (packet, to); | |
return m_rrc->SendData (packet); | |
} | |
diff -r 99bf9f9ef69a src/lte/model/lte-enb-net-device.h | |
--- a/src/lte/model/lte-enb-net-device.h Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/lte/model/lte-enb-net-device.h Thu Oct 31 19:54:48 2013 +0900 | |
@@ -120,6 +120,7 @@ | |
*/ | |
void SetUlEarfcn (uint16_t earfcn); | |
+ TracedCallback<Ptr<const Packet>, const Mac48Address&> m_traceTx; | |
protected: | |
// inherited from Object | |
diff -r 99bf9f9ef69a src/lte/model/lte-net-device.cc | |
--- a/src/lte/model/lte-net-device.cc Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/lte/model/lte-net-device.cc Thu Oct 31 19:54:48 2013 +0900 | |
@@ -59,6 +59,7 @@ | |
MakeUintegerAccessor (&LteNetDevice::SetMtu, | |
&LteNetDevice::GetMtu), | |
MakeUintegerChecker<uint16_t> ()) | |
+ .AddTraceSource ("Rx", "Receive trace", MakeTraceSourceAccessor (&LteNetDevice::m_traceRx)) | |
; | |
return tid; | |
} | |
@@ -284,6 +285,7 @@ | |
{ | |
NS_LOG_FUNCTION (this << p); | |
m_rxCallback (this, p, Ipv4L3Protocol::PROT_NUMBER, Address ()); | |
+ m_traceRx (p, Mac48Address ("00:00:00:00:00:00")); | |
} | |
diff -r 99bf9f9ef69a src/lte/model/lte-net-device.h | |
--- a/src/lte/model/lte-net-device.h Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/lte/model/lte-net-device.h Thu Oct 31 19:54:48 2013 +0900 | |
@@ -80,6 +80,8 @@ | |
virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber); | |
virtual bool SupportsSendFrom (void) const; | |
+ TracedCallback<Ptr<const Packet>, const Mac48Address&> m_traceRx; | |
+ | |
/** | |
* receive a packet from the lower layers in order to forward it to the upper layers | |
* | |
diff -r 99bf9f9ef69a src/lte/model/lte-ue-net-device.cc | |
--- a/src/lte/model/lte-ue-net-device.cc Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/lte/model/lte-ue-net-device.cc Thu Oct 31 19:54:48 2013 +0900 | |
@@ -78,6 +78,8 @@ | |
UintegerValue (0), // not used because the attribute is read-only | |
MakeUintegerAccessor (&LteUeNetDevice::m_imsi), | |
MakeUintegerChecker<uint64_t> ()) | |
+ | |
+ .AddTraceSource ("Tx", "Transmit trace", MakeTraceSourceAccessor (&LteUeNetDevice::m_traceTx)); | |
; | |
return tid; | |
@@ -205,6 +207,8 @@ | |
NS_LOG_INFO("unsupported protocol " << protocolNumber << ", only IPv4 is supported"); | |
return true; | |
} | |
+ Mac48Address to = Mac48Address::ConvertFrom (dest); | |
+ m_traceTx (packet, to); | |
return m_nas->Send (packet); | |
} | |
diff -r 99bf9f9ef69a src/lte/model/lte-ue-net-device.h | |
--- a/src/lte/model/lte-ue-net-device.h Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/lte/model/lte-ue-net-device.h Thu Oct 31 19:54:48 2013 +0900 | |
@@ -98,6 +98,7 @@ | |
*/ | |
Ptr<LteEnbNetDevice> GetTargetEnb (void); | |
+ TracedCallback<Ptr<const Packet>, const Mac48Address&> m_traceTx; | |
protected: | |
// inherited from Object | |
diff -r 99bf9f9ef69a src/visualizer/model/pyviz.cc | |
--- a/src/visualizer/model/pyviz.cc Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/visualizer/model/pyviz.cc Thu Oct 31 19:54:48 2013 +0900 | |
@@ -161,7 +161,10 @@ | |
MakeCallback (&PyViz::TraceNetDevRxWimax, this)); | |
// LTE | |
- Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx", | |
+ Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteUeNetDevice/Tx", | |
+ MakeCallback (&PyViz::TraceNetDevTxLte, this)); | |
+ | |
+ Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteEnbNetDevice/Tx", | |
MakeCallback (&PyViz::TraceNetDevTxLte, this)); | |
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx", | |
diff -r 99bf9f9ef69a src/visualizer/visualizer/plugins/exec_cmd.py | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/src/visualizer/visualizer/plugins/exec_cmd.py Thu Oct 31 19:54:48 2013 +0900 | |
@@ -0,0 +1,36 @@ | |
+import gtk | |
+ | |
+import ns.core | |
+import ns.network | |
+import ns.internet | |
+import ns.olsr | |
+ | |
+from visualizer.base import InformationWindow | |
+ | |
+import subprocess | |
+import shlex | |
+ | |
+def populate_node_menu(viz, node, menu): | |
+ ns3_node = ns.network.NodeList.GetNode(node.node_index) | |
+ | |
+ menu_item = gtk.MenuItem("Execute GDB") | |
+ menu_item.show() | |
+ | |
+ p = subprocess.Popen(['pgrep', 'mptcp'], stdout=subprocess.PIPE) | |
+ pid = p.communicate()[0] | |
+ p.wait () | |
+ | |
+ gdb_cmd_line = 'gdb -p ' + str(pid).strip() + ' -x /home/tazaki/mptcp-watch.gdb' | |
+ #gdb_cmd_line = ['gdb', '-p', str(pid).strip(), '-x', '/home/tazaki/mptcp-watch.gdb'] | |
+ print gdb_cmd_line | |
+ def _exec_cmd(dummy_menu_item): | |
+ p2 = subprocess.Popen(['gnome-terminal', '-e', gdb_cmd_line], | |
+ #p2 = subprocess.Popen(['rxvt', '-e'] + gdb_cmd_line, | |
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
+ p2.wait () | |
+ | |
+ menu_item.connect("activate", _exec_cmd) | |
+ menu.add(menu_item) | |
+ | |
+def register(viz): | |
+ viz.connect("populate-node-menu", populate_node_menu) | |
diff -r 99bf9f9ef69a src/visualizer/visualizer/plugins/lte_ue_enb_link.py | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/src/visualizer/visualizer/plugins/lte_ue_enb_link.py Thu Oct 31 19:54:48 2013 +0900 | |
@@ -0,0 +1,112 @@ | |
+import math | |
+import ns.lte | |
+import ns.network | |
+import goocanvas | |
+from visualizer.base import Link, transform_distance_canvas_to_simulation | |
+ | |
+class LteLink(Link): | |
+ def __init__(self, parent_canvas_item, sta, dev): | |
+ self.node1 = sta | |
+ self.dev = dev | |
+ self.node2 = None # ap | |
+ self.canvas_item = goocanvas.Group(parent=parent_canvas_item) | |
+ self.invisible_line = goocanvas.Polyline(parent=self.canvas_item, | |
+ line_width=25.0, | |
+ visibility=goocanvas.ITEM_HIDDEN) | |
+ self.visible_line = goocanvas.Polyline(parent=self.canvas_item, | |
+ line_width=1.0, | |
+ stroke_color_rgba=0x0000C0FF, | |
+ line_dash=goocanvas.LineDash([3.0, 3.0 ])) | |
+ self.invisible_line.props.pointer_events = (goocanvas.EVENTS_STROKE_MASK | |
+ |goocanvas.EVENTS_FILL_MASK | |
+ |goocanvas.EVENTS_PAINTED_MASK) | |
+ self.canvas_item.set_data("pyviz-object", self) | |
+ self.canvas_item.lower(None) | |
+ self.set_ap(None) | |
+ | |
+ def set_ap(self, ap): | |
+ if ap is self.node2: | |
+ return | |
+ if self.node2 is not None: | |
+ self.node2.remove_link(self) | |
+ self.node2 = ap | |
+ if self.node2 is None: | |
+ self.canvas_item.set_property("visibility", goocanvas.ITEM_HIDDEN) | |
+ else: | |
+ self.node2.add_link(self) | |
+ self.canvas_item.set_property("visibility", goocanvas.ITEM_VISIBLE) | |
+ self.update_points() | |
+ | |
+ def update_points(self): | |
+ if self.node2 is None: | |
+ return | |
+ pos1_x, pos1_y = self.node1.get_position() | |
+ pos2_x, pos2_y = self.node2.get_position() | |
+ points = goocanvas.Points([(pos1_x, pos1_y), (pos2_x, pos2_y)]) | |
+ self.visible_line.set_property("points", points) | |
+ self.invisible_line.set_property("points", points) | |
+ | |
+ def destroy(self): | |
+ self.canvas_item.destroy() | |
+ self.node1 = None | |
+ self.node2 = None | |
+ | |
+ def tooltip_query(self, tooltip): | |
+ pos1_x, pos1_y = self.node1.get_position() | |
+ pos2_x, pos2_y = self.node2.get_position() | |
+ dx = pos2_x - pos1_x | |
+ dy = pos2_y - pos1_y | |
+ d = transform_distance_canvas_to_simulation(math.sqrt(dx*dx + dy*dy)) | |
+ mac = self.dev.GetMac() | |
+ tooltip.set_text(("LTE link between UE Node %i and eNodeB %i; distance=%.2f m.\n" | |
+ ) | |
+ % (self.node1.node_index, self.node2.node_index, d)) | |
+ | |
+ | |
+class LteLinkMonitor(object): | |
+ def __init__(self, dummy_viz): | |
+ self.access_points = {} # bssid -> node | |
+ self.stations = [] # list of (sta_netdevice, viz_node, lte_link) | |
+ | |
+ def scan_nodes(self, viz): | |
+ for (ue_netdevice, viz_node, lte_link) in self.stations: | |
+ lte_link.destroy() | |
+ | |
+ self.access_points = {} | |
+ self.stations = [] | |
+ | |
+ for node in viz.nodes.itervalues(): | |
+ ns3_node = ns.network.NodeList.GetNode(node.node_index) | |
+ for devI in range(ns3_node.GetNDevices()): | |
+ dev = ns3_node.GetDevice(devI) | |
+ if not isinstance(dev, ns.lte.LteUeNetDevice) and not isinstance(dev, ns.lte.LteEnbNetDevice) : | |
+ continue | |
+ if isinstance(dev, ns.lte.LteUeNetDevice): | |
+ lte_link = LteLink(viz.links_group, node, dev) | |
+ self.stations.append((dev, node, lte_link)) | |
+ elif isinstance(dev, ns.lte.LteEnbNetDevice): | |
+ bssid = ns.network.Mac48Address.ConvertFrom(dev.GetAddress()) | |
+ self.access_points[str(bssid)] = node | |
+ #print "APs: ", self.access_points | |
+ #print "STAs: ", self.stations | |
+ | |
+ def simulation_periodic_update(self, viz): | |
+ for (ue_netdevice, viz_node, lte_link) in self.stations: | |
+ bssid = str(ns.network.Mac48Address.ConvertFrom(ue_netdevice.GetAddress())) | |
+ if bssid == '00:00:00:00:00:00:XXX': | |
+ lte_link.set_ap(None) | |
+ continue | |
+ ap = self.access_points[bssid] | |
+ lte_link.set_ap(ap) | |
+ | |
+ def update_view(self, viz): | |
+ for (dummy_ue_netdevice, dummy_viz_node, lte_link) in self.stations: | |
+ if lte_link is not None: | |
+ lte_link.update_points() | |
+ | |
+ | |
+def register(viz): | |
+ link_monitor = LteLinkMonitor(viz) | |
+ viz.connect("simulation-periodic-update", link_monitor.simulation_periodic_update) | |
+ viz.connect("update-view", link_monitor.update_view) | |
+ viz.connect("topology-scanned", link_monitor.scan_nodes) | |
diff -r 99bf9f9ef69a src/visualizer/wscript | |
--- a/src/visualizer/wscript Thu Oct 31 07:52:07 2013 +0900 | |
+++ b/src/visualizer/wscript Thu Oct 31 19:54:48 2013 +0900 | |
@@ -87,8 +87,10 @@ | |
'visualizer/plugins/interface_statistics.py', | |
'visualizer/plugins/ipv4_routing_table.py', | |
'visualizer/plugins/olsr.py', | |
+ 'visualizer/plugins/exec_cmd.py', | |
'visualizer/plugins/show_last_packets.py', | |
- 'visualizer/plugins/wifi_intrastructure_link.py' | |
+ 'visualizer/plugins/wifi_intrastructure_link.py', | |
+ 'visualizer/plugins/lte_ue_enb_link.py' | |
] | |
pyvizplug = bld(features='py') | |
pyvizplug.source = visplugin_src |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment