NS3 AddressInfo IP Prefix

Sascha Alexander Jopen <[email protected]>
Newsgroups gmane.network.routing.click
Message-ID <[email protected]>
Hey,

this is a patchset which allows the usage of AddressInfo elements within
a ns3 simulation to specify network and broadcast addresses
(device:ipnet device:bcast).

One patch (ns-3-click-ipprefix.patch) adds the required command to the
ns3 click extension, the other one (click-addressinfo-prefix-ns.patch)
extends addressinfo.cc to query the ip prefix from the simulator.

Sascha

_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click
click-addressinfo-prefix-ns.patch (text/x-patch, 1.6 KB)
diff -r -u click/elements/standard/addressinfo.cc click-patch/elements/standard/addressinfo.cc
--- click/elements/standard/addressinfo.cc	2011-09-06 14:07:30.000000000 +0200
+++ click-patch/elements/standard/addressinfo.cc	2011-09-16 17:26:28.000000000 +0200
@@ -364,6 +364,16 @@
 	int r = simclick_sim_command(context->router()->master()->simnode(), SIMCLICK_MACADDR_FROM_NAME, s.c_str(), tmp, 255);
 	if (r >= 0 && tmp[0] && EtherAddressArg().parse(tmp, store))
 	    return true;
+    } else if (context && type == 'I') {
+	char tmp[255];
+	unsigned char *ip, *prefix;
+	int r;
+	r = simclick_sim_command(context->router()->master()->simnode(), SIMCLICK_IPADDR_FROM_NAME, s.c_str(), tmp, 255);
+	if (r >= 0) {
+		r = simclick_sim_command(context->router()->master()->simnode(), SIMCLICK_IPPREFIX_FROM_NAME, s.c_str(), tmp + 16, 239);
+		if (r >= 0 && tmp[0] && tmp[16] && IPAddressArg().parse(tmp, *reinterpret_cast<IPAddress *>(store)) && IPAddressArg().parse(tmp + 16, *reinterpret_cast<IPAddress *>(store + 4)))
+			return true;
+		}
     }
 
 #endif
diff -r -u click/include/click/simclick.h click-patch/include/click/simclick.h
--- click/include/click/simclick.h	2011-09-06 14:07:30.000000000 +0200
+++ click-patch/include/click/simclick.h	2011-09-16 17:26:31.000000000 +0200
@@ -105,6 +105,7 @@
 #define SIMCLICK_GET_NEXT_PKT_ID	10 // none
 #define SIMCLICK_CHANGE_CHANNEL		11 // int ifid, int channelid
 #define SIMCLICK_IF_PROMISC		12 // int ifid
+#define SIMCLICK_IPPREFIX_FROM_NAME	13 // const char *ifname, char *buf, int len
 
 int simclick_sim_command(simclick_node_t *sim, int cmd, ...);
 int simclick_click_command(simclick_node_t *sim, int cmd, ...);
ns-3-click-ipprefix.patch (text/x-patch, 2.1 KB)
--- ns-allinone-3.11/ns-3.11/src/click/model/ipv4-click-routing.cc	2011-05-25 22:42:27.000000000 +0200
+++ ns-allinone-3.11-patched/ns-3.11/src/click/model/ipv4-click-routing.cc	2011-09-16 17:32:28.000000000 +0200
@@ -224,6 +224,15 @@
 }
 
 std::string
+Ipv4ClickRouting::GetIpPrefixFromInterfaceId (int ifid)
+{
+  std::stringstream addr;
+  m_ipv4->GetAddress (ifid, 0).GetMask ().Print (addr);
+
+  return addr.str ();
+}
+
+std::string
 Ipv4ClickRouting::GetMacAddressFromInterfaceId (int ifid)
 {
   std::stringstream addr;
@@ -586,6 +595,27 @@
         break;
       }
 
+    case SIMCLICK_IPPREFIX_FROM_NAME:
+      {
+        const char *ifname = va_arg (val, const char *);
+        char *buf = va_arg (val, char *);
+        int len = va_arg (val, int);
+
+        int ifid = clickInstance->GetInterfaceId (ifname);
+
+        if (ifid >= 0)
+          {
+            retval = simstrlcpy (buf, len, clickInstance->GetIpPrefixFromInterfaceId (ifid));
+          }
+        else
+          {
+            retval = -1;
+          }
+
+        NS_LOG_DEBUG (clickInstance->GetNodeName () << " SIMCLICK_IPPREFIX_FROM_NAME: " << ifname << " " << buf << " " << len);
+        break;
+      }
+
     case SIMCLICK_MACADDR_FROM_NAME:
       {
         const char *ifname = va_arg (val, const char *);
diff -r -u ns-allinone-3.11/ns-3.11/src/click/model/ipv4-click-routing.h ns-allinone-3.11-patched/ns-3.11/src/click/model/ipv4-click-routing.h
--- ns-allinone-3.11/ns-3.11/src/click/model/ipv4-click-routing.h	2011-05-25 22:42:27.000000000 +0200
+++ ns-allinone-3.11-patched/ns-3.11/src/click/model/ipv4-click-routing.h	2011-09-16 17:32:28.000000000 +0200
@@ -142,6 +142,13 @@
   std::string GetIpAddressFromInterfaceId (int ifid);
 
   /**
+   * \brief Provides for SIMCLICK_IPPREFIX_FROM_NAME
+   * \param ifid The interface ID for which the IP Prefix is required
+   * \return The IP Prefix of the interface in string format
+   */
+  std::string GetIpPrefixFromInterfaceId (int ifid);
+
+  /**
    * \brief Provides for SIMCLICK_MACADDR_FROM_NAME
    * \param ifid The interface ID for which the MAC Address is required
    * \return The MAC Address of the interface in string format
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.