more fixes
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 18 Apr 2011 12:13:02 +0200
changeset 63e89dca438df6
parent 62 a540fcc9a6f1
child 64 015a353a487b
more fixes
example/dce-iperf.cc
example/dce-linear.cc
example/dce-linux-simple.cc
example/dce-linux.cc
example/dce-netlink.cc
example/dce-tcp-simple.cc
example/dce-udp-perf.cc
example/dce-udp-simple.cc
example/linear-udp-perf.cc
example/wscript
helper/wscript
model/NETLINK_TODO
model/dce-manager-test.cc
model/netlink-attribute.cc
model/netlink-attribute.h
model/netlink-message-route.cc
model/netlink-message-route.h
model/netlink-message.cc
model/netlink-message.h
model/netlink-socket-address.cc
model/netlink-socket-address.h
model/netlink-socket-factory.cc
model/netlink-socket-factory.h
model/netlink-socket.cc
model/netlink-socket.h
model/netlink/TODO
model/netlink/netlink-attribute.cc
model/netlink/netlink-attribute.h
model/netlink/netlink-message-route.cc
model/netlink/netlink-message-route.h
model/netlink/netlink-message.cc
model/netlink/netlink-message.h
model/netlink/netlink-socket-address.cc
model/netlink/netlink-socket-address.h
model/netlink/netlink-socket-factory.cc
model/netlink/netlink-socket-factory.h
model/netlink/netlink-socket-test.cc
model/netlink/netlink-socket.cc
model/netlink/netlink-socket.h
model/ns3-socket-fd-factory.cc
model/task-manager.h
model/wscript
test/dce-manager-test.cc
test/netlink-socket-test.cc
wscript
     1.1 --- a/example/dce-iperf.cc	Mon Apr 18 09:01:30 2011 +0200
     1.2 +++ b/example/dce-iperf.cc	Mon Apr 18 12:13:02 2011 +0200
     1.3 @@ -1,9 +1,9 @@
     1.4 -#include "ns3/helper-module.h"
     1.5 +#include "ns3/network-module.h"
     1.6  #include "ns3/dce-application-helper.h"
     1.7  #include "ns3/dce-manager-helper.h"
     1.8 -#include "ns3/simulator-module.h"
     1.9  #include "ns3/core-module.h"
    1.10 -#include "ns3/node-module.h"
    1.11 +#include "ns3/internet-module.h"
    1.12 +#include "ns3/point-to-point-module.h"
    1.13  
    1.14  using namespace ns3;
    1.15  
     2.1 --- a/example/dce-linear.cc	Mon Apr 18 09:01:30 2011 +0200
     2.2 +++ b/example/dce-linear.cc	Mon Apr 18 12:13:02 2011 +0200
     2.3 @@ -1,9 +1,8 @@
     2.4 -#include "ns3/helper-module.h"
     2.5 -#include "ns3/dce-application-helper.h"
     2.6 -#include "ns3/dce-manager-helper.h"
     2.7 -#include "ns3/simulator-module.h"
     2.8 +#include "ns3/dce-module.h"
     2.9  #include "ns3/core-module.h"
    2.10 -#include "ns3/node-module.h"
    2.11 +#include "ns3/network-module.h"
    2.12 +#include "ns3/internet-module.h"
    2.13 +#include "ns3/point-to-point-module.h"
    2.14  #include <sys/time.h>
    2.15  #include <sys/resource.h>
    2.16  #include <fstream>
     3.1 --- a/example/dce-linux-simple.cc	Mon Apr 18 09:01:30 2011 +0200
     3.2 +++ b/example/dce-linux-simple.cc	Mon Apr 18 12:13:02 2011 +0200
     3.3 @@ -1,6 +1,6 @@
     3.4 -#include "ns3/helper-module.h"
     3.5 -#include "ns3/simulator-module.h"
     3.6 +#include "ns3/network-module.h"
     3.7  #include "ns3/core-module.h"
     3.8 +#include "ns3/dce-module.h"
     3.9  
    3.10  using namespace ns3;
    3.11  
     4.1 --- a/example/dce-linux.cc	Mon Apr 18 09:01:30 2011 +0200
     4.2 +++ b/example/dce-linux.cc	Mon Apr 18 12:13:02 2011 +0200
     4.3 @@ -1,6 +1,10 @@
     4.4 -#include "ns3/helper-module.h"
     4.5 -#include "ns3/simulator-module.h"
     4.6  #include "ns3/core-module.h"
     4.7 +#include "ns3/network-module.h"
     4.8 +#include "ns3/dce-module.h"
     4.9 +#include "ns3/point-to-point-module.h"
    4.10 +#include "ns3/csma-module.h"
    4.11 +#include "ns3/wifi-module.h"
    4.12 +#include "ns3/mobility-module.h"
    4.13  #include <fstream>
    4.14  
    4.15  using namespace ns3;
     5.1 --- a/example/dce-netlink.cc	Mon Apr 18 09:01:30 2011 +0200
     5.2 +++ b/example/dce-netlink.cc	Mon Apr 18 12:13:02 2011 +0200
     5.3 @@ -1,6 +1,6 @@
     5.4 -#include "ns3/helper-module.h"
     5.5 -#include "ns3/simulator-module.h"
     5.6  #include "ns3/core-module.h"
     5.7 +#include "ns3/dce-module.h"
     5.8 +#include "ns3/network-module.h"
     5.9  #include <fstream>
    5.10  
    5.11  using namespace ns3;
     6.1 --- a/example/dce-tcp-simple.cc	Mon Apr 18 09:01:30 2011 +0200
     6.2 +++ b/example/dce-tcp-simple.cc	Mon Apr 18 12:13:02 2011 +0200
     6.3 @@ -1,6 +1,7 @@
     6.4 -#include "ns3/helper-module.h"
     6.5 -#include "ns3/simulator-module.h"
     6.6 +#include "ns3/network-module.h"
     6.7  #include "ns3/core-module.h"
     6.8 +#include "ns3/internet-module.h"
     6.9 +#include "ns3/dce-module.h"
    6.10  
    6.11  using namespace ns3;
    6.12  
     7.1 --- a/example/dce-udp-perf.cc	Mon Apr 18 09:01:30 2011 +0200
     7.2 +++ b/example/dce-udp-perf.cc	Mon Apr 18 12:13:02 2011 +0200
     7.3 @@ -1,9 +1,8 @@
     7.4 -#include "ns3/helper-module.h"
     7.5 -#include "ns3/dce-application-helper.h"
     7.6 -#include "ns3/dce-manager-helper.h"
     7.7 -#include "ns3/simulator-module.h"
     7.8 +#include "ns3/dce-module.h"
     7.9  #include "ns3/core-module.h"
    7.10 -#include "ns3/node-module.h"
    7.11 +#include "ns3/point-to-point-module.h"
    7.12 +#include "ns3/internet-module.h"
    7.13 +#include "ns3/network-module.h"
    7.14  
    7.15  using namespace ns3;
    7.16  
     8.1 --- a/example/dce-udp-simple.cc	Mon Apr 18 09:01:30 2011 +0200
     8.2 +++ b/example/dce-udp-simple.cc	Mon Apr 18 12:13:02 2011 +0200
     8.3 @@ -1,6 +1,7 @@
     8.4 -#include "ns3/helper-module.h"
     8.5 -#include "ns3/simulator-module.h"
     8.6 +#include "ns3/network-module.h"
     8.7  #include "ns3/core-module.h"
     8.8 +#include "ns3/internet-module.h"
     8.9 +#include "ns3/dce-module.h"
    8.10  
    8.11  using namespace ns3;
    8.12  
     9.1 --- a/example/linear-udp-perf.cc	Mon Apr 18 09:01:30 2011 +0200
     9.2 +++ b/example/linear-udp-perf.cc	Mon Apr 18 12:13:02 2011 +0200
     9.3 @@ -1,10 +1,10 @@
     9.4  #include "memory-usage.h"
     9.5 -#include "ns3/helper-module.h"
     9.6 -#include "ns3/dce-application-helper.h"
     9.7 -#include "ns3/dce-manager-helper.h"
     9.8 -#include "ns3/simulator-module.h"
     9.9 +#include "ns3/network-module.h"
    9.10 +#include "ns3/dce-module.h"
    9.11  #include "ns3/core-module.h"
    9.12 -#include "ns3/node-module.h"
    9.13 +#include "ns3/internet-module.h"
    9.14 +#include "ns3/csma-module.h"
    9.15 +#include "ns3/applications-module.h"
    9.16  #include <sys/time.h>
    9.17  #include <sys/resource.h>
    9.18  #include <fstream>
    10.1 --- a/example/wscript	Mon Apr 18 09:01:30 2011 +0200
    10.2 +++ b/example/wscript	Mon Apr 18 12:13:02 2011 +0200
    10.3 @@ -51,12 +51,14 @@
    10.4  
    10.5      obj = bld.create_ns3_program('dce-linux', 
    10.6                                   ['core', 'point-to-point', 
    10.7 -                                  'internet', 'dce'])
    10.8 +                                  'internet', 'dce', 'csma', 'wifi', 'mobility'])
    10.9      obj.source = 'dce-linux.cc'
   10.10  
   10.11      obj = bld.create_dce_program('udp-perf')
   10.12      obj.env.append_value('LINKFLAGS', '-lm')
   10.13      obj.source = 'udp-perf.cc'
   10.14  
   10.15 -    obj = bld.create_ns3_program('linear-udp-perf')
   10.16 +    obj = bld.create_ns3_program('linear-udp-perf', 
   10.17 +                                 ['core', 'point-to-point', 
   10.18 +                                  'internet', 'dce'])
   10.19      obj.source = [ 'linear-udp-perf.cc', 'memory-usage.cc']
    11.1 --- a/helper/wscript	Mon Apr 18 09:01:30 2011 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,17 +0,0 @@
    11.4 -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
    11.5 -
    11.6 -def build(bld):
    11.7 -    helper = bld.create_ns3_module('dce-helper', ['internet', 'wifi', 'point-to-point', 'csma', 'olsr', 
    11.8 -                                                  'applications',
    11.9 -                                                  'dce', 'spectrum'])
   11.10 -    helper.source = [
   11.11 -        'dce-manager-helper.cc',
   11.12 -        'dce-application-helper.cc',
   11.13 -        ]
   11.14 -
   11.15 -    headers = bld.new_task_gen('ns3header')
   11.16 -    headers.module = 'helper'
   11.17 -    headers.source = [
   11.18 -        'dce-manager-helper.h',
   11.19 -        'dce-application-helper.h',
   11.20 -        ]
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/model/NETLINK_TODO	Mon Apr 18 12:13:02 2011 +0200
    12.3 @@ -0,0 +1,12 @@
    12.4 +- Notification on status change
    12.5 +- NETLINK_RTM_NEWADDR/NETLINK_RTM_DELADDR 
    12.6 +- NETLINK_RTM_SETLINK
    12.7 +   => if zebra can specify types of link
    12.8 +- NETLINK_RTM_GETLINK
    12.9 +   => Dump is implemented
   12.10 +- handle missing oif when NEW/DEL Route
   12.11 +- RT_A_SRC/RT_A_PERFSRC in NEWROUTE/DELROUTE
   12.12 +- IPv6 code (can we avoid the duplicated code btw/ v4,v6?)
   12.13 +- Multiple table from upper layer (VRF support in quagga)
   12.14 +- Doc (Doxygen)
   12.15 +- Example for netlink?
   12.16 \ No newline at end of file
    13.1 --- a/model/dce-manager-test.cc	Mon Apr 18 09:01:30 2011 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,121 +0,0 @@
    13.4 -#include "ns3/test.h"
    13.5 -#include "ns3/node.h"
    13.6 -#include "ns3/simulator.h"
    13.7 -#include "ns3/uinteger.h"
    13.8 -#include "dce-manager.h"
    13.9 -#include "task-manager.h"
   13.10 -#include "rr-task-scheduler.h"
   13.11 -#include "cooja-loader-factory.h"
   13.12 -
   13.13 -static std::string g_testError;
   13.14 -
   13.15 -extern "C" void dce_manager_test_store_test_error (const char *s)
   13.16 -{
   13.17 -  g_testError = s;
   13.18 -}
   13.19 -
   13.20 -
   13.21 -namespace ns3 {
   13.22 -
   13.23 -
   13.24 -
   13.25 -class DceManagerTestCase : public TestCase
   13.26 -{
   13.27 -public:
   13.28 -  DceManagerTestCase (std::string filename);
   13.29 -private:
   13.30 -  virtual bool DoRun (void);
   13.31 -  Ptr<DceManager> CreateManager (int *pstatus);
   13.32 -  void StartApplication (Ptr<DceManager> manager, int *pstatus);
   13.33 -  static void Finished (int *pstatus, uint16_t pid, int status);
   13.34 -
   13.35 -  std::string m_filename;
   13.36 -};
   13.37 -
   13.38 -DceManagerTestCase::DceManagerTestCase (std::string filename)
   13.39 -  : TestCase ("Check that process \"" + filename + "\" completes correctly."),
   13.40 -    m_filename (filename)
   13.41 -{}
   13.42 -void
   13.43 -DceManagerTestCase::StartApplication (Ptr<DceManager> manager, int *pstatus)
   13.44 -{
   13.45 -  std::vector<std::string> noargs;
   13.46 -  std::vector<std::pair<std::string,std::string> > noenv;
   13.47 -  
   13.48 -  uint16_t pid = manager->Start (m_filename, 1<<20, noargs, noenv);
   13.49 -  manager->SetFinishedCallback (pid, MakeBoundCallback (&DceManagerTestCase::Finished, pstatus));
   13.50 -}
   13.51 -Ptr<DceManager> 
   13.52 -DceManagerTestCase::CreateManager (int *pstatus)
   13.53 -{
   13.54 -  Ptr<Node> a = CreateObject<Node> ();
   13.55 -  Ptr<TaskManager> taskManager = CreateObject<TaskManager> ();
   13.56 -  Ptr<TaskScheduler> taskScheduler = CreateObject<RrTaskScheduler> ();
   13.57 -  Ptr<DceManager> aManager = CreateObject<DceManager> ();
   13.58 -  Ptr<LoaderFactory> loaderFactory = CreateObject<CoojaLoaderFactory> ();
   13.59 -  taskManager->SetScheduler (taskScheduler);
   13.60 -  a->AggregateObject (loaderFactory);
   13.61 -  a->AggregateObject (taskManager);
   13.62 -  a->AggregateObject (aManager);
   13.63 -  Simulator::ScheduleWithContext (a->GetId (), Seconds (0.0),
   13.64 -				  &DceManagerTestCase::StartApplication, this, 
   13.65 -				  aManager, pstatus);
   13.66 -  return aManager;
   13.67 -}
   13.68 -void
   13.69 -DceManagerTestCase::Finished (int *pstatus, uint16_t pid, int status)
   13.70 -{
   13.71 -  *pstatus = status;
   13.72 -}
   13.73 -bool
   13.74 -DceManagerTestCase::DoRun (void)
   13.75 -{
   13.76 -  int status = - 1;
   13.77 -  Ptr<DceManager> a = CreateManager (&status);
   13.78 -  Simulator::Run ();
   13.79 -  Simulator::Destroy ();
   13.80 -  NS_TEST_ASSERT_MSG_EQ (status, 0, "Process did not return successfully: " << g_testError);
   13.81 -  return status != 0;
   13.82 -}
   13.83 -
   13.84 -static class DceManagerTestSuite : public TestSuite
   13.85 -{
   13.86 -public:
   13.87 -  DceManagerTestSuite ();
   13.88 -private:
   13.89 -} g_processTests;
   13.90 -
   13.91 -DceManagerTestSuite::DceManagerTestSuite ()
   13.92 -  : TestSuite ("process-manager", UNIT)
   13.93 -{
   13.94 -  const char *tests [] = {
   13.95 -  "test-empty",
   13.96 -  "test-sleep",
   13.97 -  "test-pthread",
   13.98 -  "test-mutex",
   13.99 -  "test-once",
  13.100 -  "test-pthread-key",
  13.101 -  "test-sem",
  13.102 -  "test-malloc",
  13.103 -  "test-malloc-2",
  13.104 -  "test-fd-simple",
  13.105 -  "test-strerror",
  13.106 -  "test-stdio",
  13.107 -  "test-string",
  13.108 -  "test-netdb",
  13.109 -  "test-env",
  13.110 -  "test-cond",
  13.111 -  "test-timer-fd",
  13.112 -  "test-stdlib",
  13.113 -  "test-select",
  13.114 -  "test-nanosleep",
  13.115 -  "test-random",
  13.116 -  "test-fork",
  13.117 -  };
  13.118 -  for (unsigned int i = 0; i < sizeof(tests)/sizeof(char*);i++)
  13.119 -    {
  13.120 -      AddTestCase (new DceManagerTestCase (tests[i]));
  13.121 -    }
  13.122 -}
  13.123 -
  13.124 -} // namespace ns3
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/model/netlink-attribute.cc	Mon Apr 18 12:13:02 2011 +0200
    14.3 @@ -0,0 +1,433 @@
    14.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    14.5 +/*
    14.6 + * Copyright (c) 2008 Liu Jian
    14.7 + *
    14.8 + * This program is free software; you can redistribute it and/or modify
    14.9 + * it under the terms of the GNU General Public License version 2 as
   14.10 + * published by the Free Software Foundation;
   14.11 + *
   14.12 + * This program is distributed in the hope that it will be useful,
   14.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.15 + * GNU General Public License for more details.
   14.16 + *
   14.17 + * You should have received a copy of the GNU General Public License
   14.18 + * along with this program; if not, write to the Free Software
   14.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   14.20 + *
   14.21 + * Author: Liu Jian <liujatp@gmail.com>
   14.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   14.23 + */
   14.24 +
   14.25 +#include "netlink-attribute.h"
   14.26 +#include "netlink-message.h"
   14.27 +#include "netlink-message-route.h"
   14.28 +#include "ns3/address-utils.h"
   14.29 +
   14.30 +namespace ns3 {
   14.31 +
   14.32 +
   14.33 +/***********************************************************************************
   14.34 +* \ NetlinkAttributeValue
   14.35 +***********************************************************************************/
   14.36 +NetlinkAttributeValue::NetlinkAttributeValue ()
   14.37 +{
   14.38 +  m_type = UNSPEC;
   14.39 +  m_u32 = 0;
   14.40 +}
   14.41 +
   14.42 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v)
   14.43 +{
   14.44 +  NS_ASSERT (type == U8);
   14.45 +  m_type = U8;
   14.46 +  m_u8 = v;
   14.47 +}
   14.48 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v)
   14.49 +{
   14.50 +  NS_ASSERT (type == U16);
   14.51 +  m_type = U16;
   14.52 +  m_u16 = v;
   14.53 +}
   14.54 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v)
   14.55 +{
   14.56 +  NS_ASSERT (type == U32);
   14.57 +  m_type = U32;
   14.58 +  m_u32 = v;
   14.59 +}
   14.60 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v)
   14.61 +{
   14.62 +  NS_ASSERT (type == U64);
   14.63 +  m_type = U64;
   14.64 +  m_u64 = v;
   14.65 +}
   14.66 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v)
   14.67 +{
   14.68 +  NS_ASSERT (type == STRING);
   14.69 +  m_type = STRING;
   14.70 +  m_string = v;
   14.71 +}
   14.72 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, Address v)
   14.73 +{
   14.74 +  NS_ASSERT (type == ADDRESS);
   14.75 +  m_type = ADDRESS;
   14.76 +  m_address = v;
   14.77 +}
   14.78 +
   14.79 +void
   14.80 +NetlinkAttributeValue::SetType (NetlinkAttributeValueType type)
   14.81 +{
   14.82 +  m_type = type;
   14.83 +}
   14.84 +NetlinkAttributeValueType
   14.85 +NetlinkAttributeValue::GetType (void) const
   14.86 +{
   14.87 +  return m_type;
   14.88 +}
   14.89 +void
   14.90 +NetlinkAttributeValue::SetAddress (Address value)
   14.91 +{
   14.92 +  m_address = value;
   14.93 +}
   14.94 +void
   14.95 +NetlinkAttributeValue::SetString (std::string value)
   14.96 +{
   14.97 +  m_string = value;
   14.98 +}
   14.99 +void
  14.100 +NetlinkAttributeValue::SetU64 (uint64_t value)
  14.101 +{
  14.102 +  m_u64 = value;
  14.103 +}
  14.104 +void
  14.105 +NetlinkAttributeValue::SetU32 (uint32_t value)
  14.106 +{
  14.107 +  m_u32 = value;
  14.108 +}
  14.109 +void
  14.110 +NetlinkAttributeValue::SetU16 (uint16_t value)
  14.111 +{
  14.112 +  m_u16 = value;
  14.113 +}
  14.114 +void
  14.115 +NetlinkAttributeValue::SetU8 (uint8_t value)
  14.116 +{
  14.117 +  m_u8 = value;
  14.118 +}
  14.119 +Address
  14.120 +NetlinkAttributeValue::GetAddress (void) const
  14.121 +{
  14.122 +  return m_address;
  14.123 +}
  14.124 +std::string
  14.125 +NetlinkAttributeValue::GetString (void) const
  14.126 +{
  14.127 +  return m_string;
  14.128 +}
  14.129 +uint64_t
  14.130 +NetlinkAttributeValue::GetU64 (void) const
  14.131 +{
  14.132 +  return m_u64;
  14.133 +}
  14.134 +uint32_t
  14.135 +NetlinkAttributeValue::GetU32 (void) const
  14.136 +{
  14.137 +  return m_u32;
  14.138 +}
  14.139 +uint16_t
  14.140 +NetlinkAttributeValue::GetU16 (void) const
  14.141 +{
  14.142 +  return m_u16;
  14.143 +}
  14.144 +uint8_t
  14.145 +NetlinkAttributeValue::GetU8 (void) const
  14.146 +{
  14.147 +  return m_u8;
  14.148 +}
  14.149 +
  14.150 +void
  14.151 +NetlinkAttributeValue::Serialize (Buffer::Iterator& start) const
  14.152 +{
  14.153 +  uint32_t len;
  14.154 +
  14.155 +  if (m_type == U8)
  14.156 +    {
  14.157 +      start.WriteU8 (m_u8);
  14.158 +      len = 1;
  14.159 +    }
  14.160 +  else if(m_type == U16)
  14.161 +    {
  14.162 +      start.WriteU16 (m_u16);
  14.163 +      len = 2;
  14.164 +    }
  14.165 +  else if(m_type == U32)
  14.166 +    {
  14.167 +      start.WriteU32 (m_u32);
  14.168 +      len = 4;
  14.169 +    }
  14.170 +  else if(m_type == STRING)
  14.171 +    {
  14.172 +      start.Write ((const uint8_t *)m_string.c_str (), (uint32_t)m_string.size ()+1);
  14.173 +      len = (uint32_t)m_string.size () + 1;
  14.174 +    }
  14.175 +  else if(m_type == ADDRESS)
  14.176 +    {
  14.177 +      WriteTo (start, m_address);
  14.178 +      len = m_address.GetLength ();
  14.179 +    }
  14.180 +  else
  14.181 +    {
  14.182 +      len = 0;
  14.183 +    }
  14.184 +  //netlink align
  14.185 +  start.WriteU8 (0, NETLINK_MSG_ALIGN (len) - len);
  14.186 +}
  14.187 +
  14.188 +uint32_t
  14.189 +NetlinkAttributeValue::DeserializeWithType (Buffer::Iterator& start, 
  14.190 +                                            NetlinkAttributeValueType_e type, uint16_t remaining)
  14.191 +{
  14.192 +  uint32_t len =0;
  14.193 +  m_type = type;  
  14.194 +
  14.195 +  if (m_type == U8)
  14.196 +    {
  14.197 +      m_u8 = start.ReadU8 ();
  14.198 +      len = 1;
  14.199 +    }
  14.200 +  else if (m_type == U16)
  14.201 +    {
  14.202 +      m_u16 = start.ReadU16 ();
  14.203 +      len = 2;
  14.204 +    }
  14.205 +  else if (m_type == U32)
  14.206 +    {
  14.207 +      m_u32 = start.ReadU32 ();
  14.208 +      len = 4;
  14.209 +    }
  14.210 +  else if (m_type == U64)
  14.211 +    {
  14.212 +      m_u64 = start.ReadU64 ();
  14.213 +    }  
  14.214 +  else if (m_type == STRING)
  14.215 +    {
  14.216 +      char buf[512];
  14.217 +      uint32_t i = 0;
  14.218 +      do 
  14.219 +      {
  14.220 +        buf[i] = start.ReadU8 ();
  14.221 +      } while (buf[i++]);
  14.222 +      
  14.223 +      m_string = std::string (buf);
  14.224 +      len = (uint32_t)m_string.size () + 1;
  14.225 +    }
  14.226 +  else if (m_type == ADDRESS)
  14.227 +    {
  14.228 +      ReadFrom (start, m_address, remaining);
  14.229 +      len = m_address.GetLength ();
  14.230 +    }
  14.231 +  else
  14.232 +    {
  14.233 +      len = 0;
  14.234 +    }
  14.235 +
  14.236 +  //netlink align
  14.237 +  uint8_t buf[4];
  14.238 +  start.Read (buf, NETLINK_MSG_ALIGN (len) - len);
  14.239 +  
  14.240 +  return NETLINK_MSG_ALIGN (len);
  14.241 +}
  14.242 +
  14.243 +uint32_t
  14.244 +NetlinkAttributeValue::GetSerializedSize ()const
  14.245 +{
  14.246 +  return NETLINK_MSG_ALIGN (GetSize ());
  14.247 +}
  14.248 +
  14.249 +uint32_t
  14.250 +NetlinkAttributeValue::GetSize () const
  14.251 +{
  14.252 +  uint32_t len;
  14.253 +
  14.254 +  if (m_type == U8)
  14.255 +    {
  14.256 +      len = 1;
  14.257 +    }
  14.258 +  else if(m_type == U16)
  14.259 +    {
  14.260 +      len =  2;
  14.261 +    }
  14.262 +  else if(m_type == U32)
  14.263 +    {
  14.264 +      len =  4;
  14.265 +    }
  14.266 +  else if (m_type == STRING)
  14.267 +    {
  14.268 +      len =  uint32_t (m_string.size () + 1);
  14.269 +    }
  14.270 +  else if (m_type == ADDRESS)
  14.271 +    {
  14.272 +      len =  m_address.GetLength ();
  14.273 +    }
  14.274 +  else
  14.275 +    {
  14.276 +      len = 0;
  14.277 +    }
  14.278 +
  14.279 +    return len;
  14.280 +}
  14.281 +
  14.282 +void
  14.283 +NetlinkAttributeValue::Print (std::ostream &os) const
  14.284 +{
  14.285 +  os << "NetlinkAttributeValue (type= " << m_type <<", v= ";
  14.286 +  if (m_type == U8)
  14.287 +    {
  14.288 +      os << m_u8;
  14.289 +    }
  14.290 +  else if (m_type == U16)
  14.291 +    {
  14.292 +      os << m_u16;
  14.293 +    }
  14.294 +  else if (m_type == U32)
  14.295 +    {
  14.296 +      os << m_u32;
  14.297 +    }
  14.298 +  else if (m_type == U64)
  14.299 +    {
  14.300 +      os << m_u64;
  14.301 +    }  
  14.302 +  else if (m_type == STRING)
  14.303 +    {
  14.304 +      os << m_string;
  14.305 +    }
  14.306 +  else if (m_type == ADDRESS)
  14.307 +    {
  14.308 +      os << "address(" << m_address <<")";
  14.309 +    }
  14.310 +  else
  14.311 +    {
  14.312 +      os << "NULL";
  14.313 +    }
  14.314 +  os <<")";
  14.315 +}
  14.316 +
  14.317 +
  14.318 +/***********************************************************************************
  14.319 +* \ NetlinkAttribute
  14.320 +***********************************************************************************/
  14.321 +
  14.322 +NetlinkAttribute::NetlinkAttribute ()
  14.323 +  : m_len(4),
  14.324 +    m_type (0)
  14.325 +{
  14.326 +}
  14.327 +
  14.328 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload)
  14.329 +{
  14.330 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  14.331 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  14.332 +  m_type = type;
  14.333 +}
  14.334 +
  14.335 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload)
  14.336 +{
  14.337 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  14.338 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  14.339 +  m_type = type;
  14.340 +}
  14.341 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload)
  14.342 +{
  14.343 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  14.344 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  14.345 +  m_type = type;;
  14.346 +}
  14.347 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload)
  14.348 +{
  14.349 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  14.350 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  14.351 +  m_type = type;
  14.352 +}
  14.353 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload)
  14.354 +{
  14.355 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  14.356 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  14.357 +  m_type = type;
  14.358 +}
  14.359 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload)
  14.360 +{
  14.361 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  14.362 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  14.363 +  m_type = type;
  14.364 +}
  14.365 +
  14.366 +void
  14.367 +NetlinkAttribute::SetAttrLen (uint16_t v)
  14.368 +{
  14.369 +  m_len = v;
  14.370 +}
  14.371 +void 
  14.372 +NetlinkAttribute::SetAttrType (uint16_t v)
  14.373 +{
  14.374 +  m_type = v;
  14.375 +}
  14.376 +void
  14.377 +NetlinkAttribute::SetAttrPayload (NetlinkAttributeValue v)
  14.378 +{
  14.379 +  m_payload = v;
  14.380 +}
  14.381 +uint16_t
  14.382 +NetlinkAttribute::GetAttrLen () const
  14.383 +{
  14.384 +  return m_len;
  14.385 +}
  14.386 +uint16_t
  14.387 +NetlinkAttribute::GetAttrType () const
  14.388 +{
  14.389 +  return m_type;
  14.390 +}
  14.391 +NetlinkAttributeValue
  14.392 +NetlinkAttribute::GetAttrPayload() const
  14.393 +{
  14.394 +  return m_payload;
  14.395 +}
  14.396 +
  14.397 +void 
  14.398 +NetlinkAttribute::Print (std::ostream &os) const
  14.399 +{  
  14.400 +  os << "NetlinkAttribute "
  14.401 +     << "len: " << m_len << " "
  14.402 +     << "type: " << m_type<<" "
  14.403 +     << "payload:[";
  14.404 +  m_payload.Print(os);
  14.405 +  os<<"]";
  14.406 +}
  14.407 +
  14.408 +uint32_t 
  14.409 +NetlinkAttribute::GetSerializedSize (void) const
  14.410 +{
  14.411 +  /* this is the size of an nlattr payload. */
  14.412 +  return NETLINK_MSG_ATTR_SIZE + m_payload.GetSerializedSize ();
  14.413 +}
  14.414 +
  14.415 +void
  14.416 +NetlinkAttribute::Serialize (Buffer::Iterator& start) const
  14.417 +{
  14.418 +  start.WriteU16 (m_len);
  14.419 +  start.WriteU16 (m_type);
  14.420 +  m_payload.Serialize (start);
  14.421 +}
  14.422 +
  14.423 +uint32_t
  14.424 +NetlinkAttribute::Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[])
  14.425 +{
  14.426 +  NetlinkAttributeValueType type;
  14.427 +
  14.428 +  m_len = start.ReadU16 ();
  14.429 +  m_type = start.ReadU16 ();
  14.430 +  type = vtypes[m_type];
  14.431 +  m_payload.DeserializeWithType (start, type, m_len - 4);
  14.432 +
  14.433 +  return GetSerializedSize ();
  14.434 +}
  14.435 +
  14.436 +}; // namespace ns3
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/model/netlink-attribute.h	Mon Apr 18 12:13:02 2011 +0200
    15.3 @@ -0,0 +1,124 @@
    15.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    15.5 +/*
    15.6 + * Copyright (c) 2008 Liu Jian
    15.7 + *
    15.8 + * This program is free software; you can redistribute it and/or modify
    15.9 + * it under the terms of the GNU General Public License version 2 as
   15.10 + * published by the Free Software Foundation;
   15.11 + *
   15.12 + * This program is distributed in the hope that it will be useful,
   15.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.15 + * GNU General Public License for more details.
   15.16 + *
   15.17 + * You should have received a copy of the GNU General Public License
   15.18 + * along with this program; if not, write to the Free Software
   15.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.20 + *
   15.21 + * Author: Liu Jian <liujatp@gmail.com>
   15.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   15.23 + */
   15.24 +
   15.25 +#ifndef NETLINK_ATTRIBUTE_H
   15.26 +#define NETLINK_ATTRIBUTE_H
   15.27 +
   15.28 +
   15.29 +#include <stdint.h>
   15.30 +#include <string>
   15.31 +#include <ostream>
   15.32 +#include "ns3/address.h"
   15.33 +#include "ns3/buffer.h"
   15.34 +
   15.35 +namespace ns3 {
   15.36 +
   15.37 +/**
   15.38 +* \brief The Netlink Attribute
   15.39 +*/
   15.40 +
   15.41 +typedef enum NetlinkAttributeValueType_e {
   15.42 +  UNSPEC, // invalid initial value.
   15.43 +  U8,
   15.44 +  U16,
   15.45 +  U32,
   15.46 +  U64,
   15.47 +  STRING,
   15.48 +  ADDRESS,
   15.49 +}NetlinkAttributeValueType;
   15.50 +
   15.51 +class NetlinkAttributeValue
   15.52 +{
   15.53 +public:
   15.54 +  NetlinkAttributeValue ();
   15.55 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v);
   15.56 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v);
   15.57 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v);
   15.58 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v);
   15.59 +  NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v);
   15.60 +  NetlinkAttributeValue (NetlinkAttributeValueType type, Address v);
   15.61 +  
   15.62 +  void Serialize (Buffer::Iterator& start) const;
   15.63 +  uint32_t DeserializeWithType (Buffer::Iterator& start, NetlinkAttributeValueType type, uint16_t remaining);
   15.64 +  uint32_t GetSerializedSize (void) const;
   15.65 +  uint32_t GetSize (void) const;
   15.66 +  void Print (std::ostream &os) const;
   15.67 +
   15.68 +  void SetType (NetlinkAttributeValueType type);
   15.69 +  NetlinkAttributeValueType GetType (void) const;
   15.70 +  void SetAddress (Address value);
   15.71 +  void SetString (std::string value);
   15.72 +  void SetU64 (uint64_t value);
   15.73 +  void SetU32 (uint32_t value);
   15.74 +  void SetU16 (uint16_t value);
   15.75 +  void SetU8 (uint8_t value);
   15.76 +  Address GetAddress (void) const;
   15.77 +  std::string GetString (void) const;
   15.78 +  uint64_t GetU64 (void) const;
   15.79 +  uint32_t GetU32 (void) const;
   15.80 +  uint16_t GetU16 (void) const;
   15.81 +  uint8_t GetU8 (void) const;
   15.82 +
   15.83 +private:
   15.84 +  NetlinkAttributeValueType m_type;
   15.85 +  uint64_t m_u64;
   15.86 +  uint32_t m_u32;
   15.87 +  uint16_t m_u16;
   15.88 +  uint8_t m_u8;
   15.89 +  std::string m_string;
   15.90 +  Address m_address;
   15.91 +};
   15.92 +
   15.93 +struct NetlinkAttribute
   15.94 +{
   15.95 +public:
   15.96 +  NetlinkAttribute ();
   15.97 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload);
   15.98 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload);
   15.99 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload);
  15.100 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload);
  15.101 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload);
  15.102 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload);
  15.103 +
  15.104 +  //static TypeId GetTypeId (void);
  15.105 +  //virtual TypeId GetInstanceTypeId (void) const;
  15.106 +  void Print (std::ostream &os) const;
  15.107 +  uint32_t GetSerializedSize (void) const;
  15.108 +  void Serialize (Buffer::Iterator& start) const;
  15.109 +  uint32_t Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[]);
  15.110 +
  15.111 +  void SetAttrLen (uint16_t v);
  15.112 +  void SetAttrType (uint16_t v);
  15.113 +  void SetAttrPayload (NetlinkAttributeValue v);
  15.114 +  uint16_t GetAttrLen () const;
  15.115 +  uint16_t GetAttrType () const;
  15.116 +  NetlinkAttributeValue GetAttrPayload () const;
  15.117 +
  15.118 +private:
  15.119 +  static const int NETLINK_MSG_ATTR_SIZE = 4; /* size of the nlattr field*/
  15.120 +  uint16_t m_len;
  15.121 +  uint16_t m_type; 
  15.122 +  NetlinkAttributeValue m_payload;
  15.123 +};
  15.124 +
  15.125 +}; // namespace ns3
  15.126 +
  15.127 +#endif /* NETLINK_ATTRIBUTE_H */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/model/netlink-message-route.cc	Mon Apr 18 12:13:02 2011 +0200
    16.3 @@ -0,0 +1,647 @@
    16.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    16.5 +/*
    16.6 + * Copyright (c) 2008 Liu Jian
    16.7 + *
    16.8 + * This program is free software; you can redistribute it and/or modify
    16.9 + * it under the terms of the GNU General Public License version 2 as
   16.10 + * published by the Free Software Foundation;
   16.11 + *
   16.12 + * This program is distributed in the hope that it will be useful,
   16.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.15 + * GNU General Public License for more details.
   16.16 + *
   16.17 + * You should have received a copy of the GNU General Public License
   16.18 + * along with this program; if not, write to the Free Software
   16.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   16.20 + *
   16.21 + * Author: Liu Jian <liujatp@gmail.com>
   16.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   16.23 + */
   16.24 +
   16.25 +#include "netlink-message-route.h"
   16.26 +#include "netlink-message.h"
   16.27 +
   16.28 +namespace ns3 {
   16.29 +
   16.30 +/***********************************************************************************
   16.31 +* \ NetlinkPayload
   16.32 +***********************************************************************************/
   16.33 +TypeId 
   16.34 +NetlinkPayload::GetTypeId (void)
   16.35 +{
   16.36 +  static TypeId tid = TypeId ("ns3::NetlinkPayload")
   16.37 +    .SetParent<ObjectBase> ()
   16.38 +    ;
   16.39 +  return tid;
   16.40 +}
   16.41 +
   16.42 +
   16.43 +/***********************************************************************************
   16.44 +* \ GeneralMessage
   16.45 +***********************************************************************************/
   16.46 +
   16.47 +NS_OBJECT_ENSURE_REGISTERED (GeneralMessage);
   16.48 +NS_OBJECT_ENSURE_REGISTERED (InterfaceInfoMessage);
   16.49 +NS_OBJECT_ENSURE_REGISTERED (InterfaceAddressMessage);
   16.50 +NS_OBJECT_ENSURE_REGISTERED (RouteMessage);
   16.51 +
   16.52 +GeneralMessage::GeneralMessage ()
   16.53 +  : m_family(0)
   16.54 +{}
   16.55 +GeneralMessage::~GeneralMessage ()
   16.56 +{}
   16.57 +
   16.58 +void
   16.59 +GeneralMessage::SetFamily (uint8_t v)
   16.60 +{
   16.61 +  m_family = v;
   16.62 +}
   16.63 +uint8_t
   16.64 +GeneralMessage::GetFamily (void) const
   16.65 +{
   16.66 +  return m_family;
   16.67 +}
   16.68 +
   16.69 +TypeId 
   16.70 +GeneralMessage::GetTypeId (void)
   16.71 +{
   16.72 +  static TypeId tid = TypeId ("ns3::GeneralMessage")
   16.73 +    .SetParent<NetlinkPayload> ()
   16.74 +    .AddConstructor<GeneralMessage> ()
   16.75 +    ;
   16.76 +  return tid;
   16.77 +}
   16.78 +
   16.79 +TypeId 
   16.80 +GeneralMessage::GetInstanceTypeId (void) const
   16.81 +{
   16.82 +  return GetTypeId ();
   16.83 +}
   16.84 +void 
   16.85 +GeneralMessage::Print (std::ostream &os) const
   16.86 +{
   16.87 +  os << " ----GeneralMessage ("
   16.88 +     << "family: " << (uint32_t)m_family << ")"; 
   16.89 +}
   16.90 +
   16.91 +uint32_t 
   16.92 +GeneralMessage::GetSerializedSize (void) const
   16.93 +{
   16.94 +  /* this is the size of an nlmsghdr payload. */
   16.95 +  return NETLINK_MSG_ALIGN (NETLINK_GENMSG_SIZE);
   16.96 +}
   16.97 +
   16.98 +
   16.99 +void
  16.100 +GeneralMessage::Serialize (Buffer::Iterator& start) const
  16.101 +{
  16.102 +  start.WriteU8 (m_family);
  16.103 +  start.WriteU8 (0, 3);
  16.104 +}
  16.105 +
  16.106 +uint32_t
  16.107 +GeneralMessage::Deserialize (Buffer::Iterator& start)
  16.108 +{
  16.109 +  uint8_t buf[3];
  16.110 +  m_family = start.ReadU8 ();
  16.111 +  start.Read (buf, 3);
  16.112 +  return GetSerializedSize ();
  16.113 +}
  16.114 +uint32_t
  16.115 +GeneralMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  16.116 +{
  16.117 +  uint8_t buf[3];
  16.118 +  m_family = start.ReadU8 ();
  16.119 +  start.Read (buf, 3);
  16.120 +  return GetSerializedSize ();
  16.121 +}
  16.122 +
  16.123 +
  16.124 +uint32_t
  16.125 +GeneralMessage::GetNNetlinkAttribute (void)const
  16.126 +{
  16.127 +  return m_attributes.size ();
  16.128 +}
  16.129 +NetlinkAttribute
  16.130 +GeneralMessage::GetNetlinkAttribute (uint32_t index)const
  16.131 +{
  16.132 +  NS_ASSERT(index < GetNNetlinkAttribute ());
  16.133 +  return m_attributes[index];
  16.134 +}
  16.135 +
  16.136 +uint32_t
  16.137 +GeneralMessage::GetAttributeSerializedSize (void) const
  16.138 +{
  16.139 +  uint32_t size = 0;
  16.140 +
  16.141 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  16.142 +    {
  16.143 +      size += m_attributes[i].GetSerializedSize ();
  16.144 +    }
  16.145 +  return size;
  16.146 +}
  16.147 +bool
  16.148 +GeneralMessage::GetAttributeByType (NetlinkAttribute& attr, uint16_t type)
  16.149 +{
  16.150 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  16.151 +    {
  16.152 +      if (type == m_attributes[i].GetAttrType ())
  16.153 +        {
  16.154 +          attr = m_attributes[i];
  16.155 +          return true;
  16.156 +        }
  16.157 +    }
  16.158 +  return false;  
  16.159 +}
  16.160 +void
  16.161 +GeneralMessage::AppendAttribute (NetlinkAttribute v)
  16.162 +{
  16.163 +  m_attributes.push_back (v);
  16.164 +}
  16.165 +
  16.166 +void
  16.167 +GeneralMessage::SerializeAttribute (Buffer::Iterator& start) const
  16.168 +{
  16.169 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  16.170 +    {
  16.171 +      m_attributes[i].Serialize (start);
  16.172 +    }
  16.173 +}
  16.174 +
  16.175 +void
  16.176 +GeneralMessage::PrintAttribute (std::ostream &os) const
  16.177 +{
  16.178 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  16.179 +    {
  16.180 +      os << " ----Attribute (" << i << "):";
  16.181 +      m_attributes[i].Print(os);
  16.182 +    }
  16.183 +}
  16.184 +
  16.185 +/***********************************************************************************
  16.186 +* \ InterfaceInfoMessage
  16.187 +***********************************************************************************/
  16.188 +InterfaceInfoMessage::InterfaceInfoMessage ()
  16.189 +  : m_reserved (0),
  16.190 +    m_deviceType (0),
  16.191 +    m_interfaceIndex(0),
  16.192 +    m_deviceFlags (0),
  16.193 +    m_changeMask (0)
  16.194 +{
  16.195 +  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  16.196 +  m_attributeTypes[IFL_A_UNSPEC] = UNSPEC;
  16.197 +  m_attributeTypes[IFL_A_ADDRESS] = ADDRESS;
  16.198 +  m_attributeTypes[IFL_A_BROADCAST] = ADDRESS;
  16.199 +  m_attributeTypes[IFL_A_IFNAME] = STRING;
  16.200 +  m_attributeTypes[IFL_A_MTU] = U32;
  16.201 +  m_attributeTypes[IFL_A_LINK] = U32;
  16.202 +  m_attributeTypes[IFL_A_QDISC] = U8;
  16.203 +  m_attributeTypes[IFL_A_STATS] = UNSPEC;
  16.204 +  m_attributeTypes[IFL_A_COST] = UNSPEC;
  16.205 +}
  16.206 +InterfaceInfoMessage::~InterfaceInfoMessage ()
  16.207 +{}
  16.208 +void
  16.209 +InterfaceInfoMessage::SetDeviceType (uint16_t type)
  16.210 +{
  16.211 +  m_deviceType = type;
  16.212 +}
  16.213 +void
  16.214 +InterfaceInfoMessage::SetInterfaceIndex (int32_t index)
  16.215 +{
  16.216 +  m_interfaceIndex = index;
  16.217 +}
  16.218 +void
  16.219 +InterfaceInfoMessage::SetDeviceFlags (uint32_t flags)
  16.220 +{
  16.221 +  m_deviceFlags = flags;
  16.222 +}
  16.223 +void
  16.224 +InterfaceInfoMessage::SetChangeMask (uint32_t mask)
  16.225 +{
  16.226 +  m_changeMask = mask;
  16.227 +}
  16.228 +uint16_t
  16.229 +InterfaceInfoMessage::GetDeviceType (void) const
  16.230 +{
  16.231 +  return m_deviceType;
  16.232 +}
  16.233 +int32_t
  16.234 +InterfaceInfoMessage::GetInterfaceIndex (void) const
  16.235 +{
  16.236 +  return m_interfaceIndex;
  16.237 +}
  16.238 +uint32_t
  16.239 +InterfaceInfoMessage::GetDeviceFlags (void) const
  16.240 +{
  16.241 +  return m_deviceFlags;
  16.242 +}
  16.243 +uint32_t
  16.244 +InterfaceInfoMessage::GetChangeMask (void) const
  16.245 +{
  16.246 +  return m_changeMask;
  16.247 +}
  16.248 +TypeId 
  16.249 +InterfaceInfoMessage::GetTypeId (void)
  16.250 +{
  16.251 +  static TypeId tid = TypeId ("ns3::InterfaceInfoMessage")
  16.252 +    .SetParent<GeneralMessage> ()
  16.253 +    .AddConstructor<InterfaceInfoMessage> ()
  16.254 +    ;
  16.255 +  return tid;
  16.256 +}
  16.257 +TypeId 
  16.258 +InterfaceInfoMessage::GetInstanceTypeId (void) const
  16.259 +{
  16.260 +  return GetTypeId ();
  16.261 +}
  16.262 +void 
  16.263 +InterfaceInfoMessage::Print (std::ostream &os) const
  16.264 +{  
  16.265 +  os << " ----InterfaceInfoMessage ("
  16.266 +     << "deviceType: " << m_deviceType << " "
  16.267 +     << "interfaceIndex: " << m_interfaceIndex << " "
  16.268 +     << "deviceFlags: " << m_deviceFlags << " "
  16.269 +     << "changeMask: " << m_changeMask << ")" ;
  16.270 +  PrintAttribute (os);
  16.271 +}
  16.272 +uint32_t 
  16.273 +InterfaceInfoMessage::GetSerializedSize (void) const
  16.274 +{
  16.275 +  return NETLINK_INTERFACE_SIZE + GetAttributeSerializedSize ();
  16.276 +}
  16.277 +
  16.278 +void
  16.279 +InterfaceInfoMessage::Serialize (Buffer::Iterator& start) const
  16.280 +{
  16.281 +  start.WriteU8 (m_family);
  16.282 +  start.WriteU8 (m_reserved);
  16.283 +  start.WriteU16 (m_deviceType);
  16.284 +  start.WriteU32 (m_interfaceIndex);
  16.285 +  start.WriteU32 (m_deviceFlags);
  16.286 +  start.WriteU32 (m_changeMask);
  16.287 +
  16.288 +  SerializeAttribute (start);
  16.289 +}
  16.290 +uint32_t
  16.291 +InterfaceInfoMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  16.292 +{
  16.293 +  m_family = start.ReadU8 ();
  16.294 +  m_reserved = start.ReadU8 ();
  16.295 +  m_deviceType = start.ReadU16 ();
  16.296 +  m_interfaceIndex = start.ReadU32 ();
  16.297 +  m_deviceFlags = start.ReadU32 ();
  16.298 +  m_changeMask = start.ReadU32 ();
  16.299 +
  16.300 +  len -= NETLINK_INTERFACE_SIZE;
  16.301 +
  16.302 +  while (len)
  16.303 +    {
  16.304 +      NetlinkAttribute attr;
  16.305 +
  16.306 +      len -= attr.Deserialize (start, m_attributeTypes);
  16.307 +      m_attributes.push_back (attr);
  16.308 +    }
  16.309 +
  16.310 +  return GetSerializedSize ();
  16.311 +}
  16.312 +
  16.313 +
  16.314 +
  16.315 +/***********************************************************************************
  16.316 +* \InterfaceAddressMessage
  16.317 +***********************************************************************************/
  16.318 +InterfaceAddressMessage::InterfaceAddressMessage ()
  16.319 +  : m_length (0),
  16.320 +    m_flags (0),
  16.321 +    m_scope (0),
  16.322 +    m_index(0)
  16.323 +{
  16.324 +  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  16.325 +  m_attributeTypes[IF_A_UNSPEC] = UNSPEC;
  16.326 +  m_attributeTypes[IF_A_ADDRESS] = ADDRESS;
  16.327 +  m_attributeTypes[IF_A_LOCAL] = ADDRESS;
  16.328 +  m_attributeTypes[IF_A_LABEL] = STRING;
  16.329 +  m_attributeTypes[IF_A_BROADCAST] = ADDRESS;
  16.330 +  m_attributeTypes[IF_A_ANYCAST] = ADDRESS;
  16.331 +  m_attributeTypes[IF_A_CACHEINFO] = UNSPEC;
  16.332 +  m_attributeTypes[IF_A_MULTICAST] = ADDRESS;
  16.333 +}
  16.334 +InterfaceAddressMessage::~InterfaceAddressMessage ()
  16.335 +{
  16.336 +}
  16.337 +void
  16.338 +InterfaceAddressMessage::SetFamily (uint8_t family)
  16.339 +{
  16.340 +  m_family = family;
  16.341 +}
  16.342 +void
  16.343 +InterfaceAddressMessage::SetLength (uint8_t length)
  16.344 +{
  16.345 +  m_length = length;
  16.346 +}
  16.347 +void
  16.348 +InterfaceAddressMessage::SetFlags (uint8_t flags)
  16.349 +{
  16.350 +  m_flags = flags;
  16.351 +}
  16.352 +void
  16.353 +InterfaceAddressMessage::SetScope (uint8_t scope)
  16.354 +{
  16.355 +  m_scope = scope;
  16.356 +}
  16.357 +void
  16.358 +InterfaceAddressMessage::SetInterfaceIndex (int32_t index)
  16.359 +{
  16.360 +  m_index = index;
  16.361 +}
  16.362 +
  16.363 +uint8_t
  16.364 +InterfaceAddressMessage::GetFamily (void) const
  16.365 +{
  16.366 +  return m_family;
  16.367 +}
  16.368 +uint8_t
  16.369 +InterfaceAddressMessage::GetLength (void) const
  16.370 +{
  16.371 +  return m_length;
  16.372 +}
  16.373 +uint8_t
  16.374 +InterfaceAddressMessage::GetFlags (void) const
  16.375 +{
  16.376 +  return m_flags;
  16.377 +}
  16.378 +uint8_t
  16.379 +InterfaceAddressMessage::GetScope (void) const
  16.380 +{
  16.381 +  return m_scope;
  16.382 +}
  16.383 +int32_t
  16.384 +InterfaceAddressMessage::GetInterfaceIndex (void) const
  16.385 +{
  16.386 +  return m_index;
  16.387 +}
  16.388 +
  16.389 +TypeId 
  16.390 +InterfaceAddressMessage::GetTypeId (void)
  16.391 +{
  16.392 +  static TypeId tid = TypeId ("ns3::InterfaceAddressMessage")
  16.393 +    .SetParent<GeneralMessage> ()
  16.394 +    .AddConstructor<InterfaceAddressMessage> ()
  16.395 +    ;
  16.396 +  return tid;
  16.397 +}
  16.398 +TypeId 
  16.399 +InterfaceAddressMessage::GetInstanceTypeId (void) const
  16.400 +{
  16.401 +  return GetTypeId ();
  16.402 +}
  16.403 +void 
  16.404 +InterfaceAddressMessage::Print (std::ostream &os) const
  16.405 +{  
  16.406 +  os << " ----InterfaceAddressMessage ("
  16.407 +     << "family: " << (uint32_t)m_family << " "
  16.408 +     << "length: " << (uint32_t)m_length << " "
  16.409 +     << "flags: " << (uint32_t)m_flags << " "
  16.410 +     << "scope: " << (uint32_t)m_scope << " "
  16.411 +     << "index: " << m_index << ")";
  16.412 +  PrintAttribute (os);
  16.413 +}
  16.414 +uint32_t 
  16.415 +InterfaceAddressMessage::GetSerializedSize (void) const
  16.416 +{
  16.417 +  return NETLINK_ADDRESS_SIZE + GetAttributeSerializedSize ();
  16.418 +}
  16.419 +
  16.420 +void
  16.421 +InterfaceAddressMessage::Serialize (Buffer::Iterator& start) const
  16.422 +{
  16.423 +  start.WriteU8 (m_family);
  16.424 +  start.WriteU8 (m_length);
  16.425 +  start.WriteU8 (m_flags);
  16.426 +  start.WriteU8 (m_scope);
  16.427 +  start.WriteU32 (m_index);
  16.428 +
  16.429 +  SerializeAttribute(start);
  16.430 +}
  16.431 +
  16.432 +uint32_t
  16.433 +InterfaceAddressMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  16.434 +{
  16.435 +  m_family = start.ReadU8 ();
  16.436 +  m_length = start.ReadU8 ();
  16.437 +  m_flags = start.ReadU8 ();
  16.438 +  m_scope = start.ReadU8 ();
  16.439 +  m_index = start.ReadU32 ();
  16.440 +
  16.441 +  len -= NETLINK_ADDRESS_SIZE;
  16.442 +
  16.443 +  while (len)
  16.444 +    {
  16.445 +      NetlinkAttribute attr;
  16.446 +
  16.447 +      len -= attr.Deserialize (start, m_attributeTypes);
  16.448 +      m_attributes.push_back (attr);
  16.449 +    }
  16.450 +
  16.451 +  return GetSerializedSize ();
  16.452 +}
  16.453 +
  16.454 +
  16.455 +
  16.456 +/***********************************************************************************
  16.457 +* \ RouteMessage
  16.458 +***********************************************************************************/
  16.459 +RouteMessage::RouteMessage ()
  16.460 +  : m_dstLen (0),
  16.461 +    m_srcLen (0),
  16.462 +    m_tos (0),
  16.463 +    m_tableId (0),
  16.464 +    m_protocol(0),
  16.465 +    m_scope (0),
  16.466 +    m_type (0),
  16.467 +    m_flags (0)
  16.468 +{
  16.469 +  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  16.470 +  m_attributeTypes[RT_A_UNSPEC] = UNSPEC;
  16.471 +  m_attributeTypes[RT_A_DST] = ADDRESS;
  16.472 +  m_attributeTypes[RT_A_SRC] = ADDRESS;
  16.473 +  m_attributeTypes[RT_A_IIF] = U32;
  16.474 +  m_attributeTypes[RT_A_OIF] = U32;
  16.475 +  m_attributeTypes[RT_A_GATEWAY] = ADDRESS;
  16.476 +  m_attributeTypes[RT_A_PRIORITY] = U8;
  16.477 +  m_attributeTypes[RT_A_PREFSRC] = ADDRESS;
  16.478 +  m_attributeTypes[RT_A_METRICS] = UNSPEC;
  16.479 +  //others default value UNSPEC
  16.480 +}
  16.481 +RouteMessage::~RouteMessage ()
  16.482 +{}
  16.483 +
  16.484 +void
  16.485 +RouteMessage::SetFamily (uint8_t v)
  16.486 +{
  16.487 +  m_family = v;
  16.488 +}
  16.489 +void
  16.490 +RouteMessage::SetDstLength (uint8_t v)
  16.491 +{
  16.492 +  m_dstLen = v;
  16.493 +}
  16.494 +void
  16.495 +RouteMessage::SetSrcLength (uint8_t v)
  16.496 +{
  16.497 +  m_srcLen = v;
  16.498 +}
  16.499 +void
  16.500 +RouteMessage::SetTos (uint8_t v)
  16.501 +{
  16.502 +  m_tos = v;
  16.503 +}
  16.504 +void
  16.505 +RouteMessage::SetTableId (uint8_t v)
  16.506 +{
  16.507 +  m_tableId = v;
  16.508 +}
  16.509 +void
  16.510 +RouteMessage::SetProtocol (uint8_t v)
  16.511 +{
  16.512 +  m_protocol = v;
  16.513 +}
  16.514 +void
  16.515 +RouteMessage::SetScope (uint8_t v)
  16.516 +{
  16.517 +  m_scope = v;
  16.518 +}
  16.519 +void
  16.520 +RouteMessage::SetType (uint8_t v)
  16.521 +{
  16.522 +  m_type = v;
  16.523 +}
  16.524 +void
  16.525 +RouteMessage::SetFlags (uint32_t v)
  16.526 +{
  16.527 +  m_flags = v;
  16.528 +}
  16.529 +uint8_t
  16.530 +RouteMessage::GetFamily (void) const
  16.531 +{
  16.532 +  return m_family;
  16.533 +}
  16.534 +uint8_t
  16.535 +RouteMessage::GetDstLength (void) const
  16.536 +{
  16.537 +  return m_dstLen;
  16.538 +}
  16.539 +uint8_t
  16.540 +RouteMessage::GetSrcLength (void) const
  16.541 +{
  16.542 +  return m_srcLen;
  16.543 +}
  16.544 +uint8_t
  16.545 +RouteMessage::GetTos (void) const
  16.546 +{
  16.547 +  return m_tos;
  16.548 +}
  16.549 +uint8_t
  16.550 +RouteMessage::GetTableId (void) const
  16.551 +{
  16.552 +  return m_tableId;
  16.553 +}
  16.554 +uint8_t
  16.555 +RouteMessage::GetProtocol (void) const
  16.556 +{
  16.557 +  return m_protocol;
  16.558 +}
  16.559 +uint8_t
  16.560 +RouteMessage::GetType (void) const
  16.561 +{
  16.562 +  return m_type;
  16.563 +}
  16.564 +uint8_t
  16.565 +RouteMessage::GetScope (void) const
  16.566 +{
  16.567 +  return m_scope;
  16.568 +}
  16.569 +uint32_t
  16.570 +RouteMessage::GetFlags (void) const
  16.571 +{
  16.572 +  return m_flags;
  16.573 +}
  16.574 +
  16.575 +TypeId 
  16.576 +RouteMessage::GetTypeId (void)
  16.577 +{
  16.578 +  static TypeId tid = TypeId ("ns3::RouteMessage")
  16.579 +    .SetParent<GeneralMessage> ()
  16.580 +    .AddConstructor<RouteMessage> ()
  16.581 +    ;
  16.582 +  return tid;
  16.583 +}
  16.584 +TypeId 
  16.585 +RouteMessage::GetInstanceTypeId (void) const
  16.586 +{
  16.587 +  return GetTypeId ();
  16.588 +}
  16.589 +void 
  16.590 +RouteMessage::Print (std::ostream &os) const
  16.591 +{  
  16.592 +  os << " ----RouteMessage ("
  16.593 +     << "family: " << (uint32_t)m_family << " "
  16.594 +     << "dstLen: " << (uint32_t)m_dstLen << " "
  16.595 +     << "srcLen: " << (uint32_t)m_srcLen << " "
  16.596 +     << "tos: " << (uint32_t)m_tos << " "
  16.597 +     << "tableId: " << (uint32_t)m_tableId << " "
  16.598 +     << "protocol: " << (uint32_t)m_protocol << " "
  16.599 +     << "scope: " << (uint32_t)m_scope << " "
  16.600 +     << "type: " << (uint32_t)m_type << " "
  16.601 +     << "flags: " << m_flags<< ")" ;
  16.602 +  PrintAttribute (os);
  16.603 +}
  16.604 +uint32_t 
  16.605 +RouteMessage::GetSerializedSize (void) const
  16.606 +{
  16.607 +  return NETLINK_ROUTE_SIZE + GetAttributeSerializedSize ();
  16.608 +}
  16.609 +
  16.610 +void
  16.611 +RouteMessage::Serialize (Buffer::Iterator& start) const
  16.612 +{
  16.613 +  start.WriteU8 (m_family);
  16.614 +  start.WriteU8 (m_dstLen);
  16.615 +  start.WriteU8 (m_srcLen);
  16.616 +  start.WriteU8 (m_tos);
  16.617 +  start.WriteU8 (m_tableId);
  16.618 +  start.WriteU8 (m_protocol);
  16.619 +  start.WriteU8 (m_scope);
  16.620 +  start.WriteU8 (m_type);
  16.621 +  start.WriteU32 (m_flags);
  16.622 +
  16.623 +  SerializeAttribute (start);
  16.624 +}
  16.625 +uint32_t
  16.626 +RouteMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  16.627 +{
  16.628 +  m_family = start.ReadU8 ();
  16.629 +  m_dstLen = start.ReadU8 ();
  16.630 +  m_srcLen = start.ReadU8 ();
  16.631 +  m_tos = start.ReadU8 ();
  16.632 +  m_tableId = start.ReadU8 ();
  16.633 +  m_protocol = start.ReadU8 ();
  16.634 +  m_scope = start.ReadU8 ();
  16.635 +  m_type = start.ReadU8 ();
  16.636 +  m_flags = start.ReadU32 ();
  16.637 +
  16.638 +  len -= NETLINK_ROUTE_SIZE;
  16.639 +
  16.640 +  while (len)
  16.641 +    {
  16.642 +      NetlinkAttribute attr;
  16.643 +
  16.644 +      len -= attr.Deserialize (start, m_attributeTypes);
  16.645 +      m_attributes.push_back (attr);
  16.646 +    }
  16.647 +
  16.648 +  return GetSerializedSize ();
  16.649 +}
  16.650 +}; // namespace ns3
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/model/netlink-message-route.h	Mon Apr 18 12:13:02 2011 +0200
    17.3 @@ -0,0 +1,388 @@
    17.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    17.5 +/*
    17.6 + * Copyright (c) 2008 Liu Jian
    17.7 + *
    17.8 + * This program is free software; you can redistribute it and/or modify
    17.9 + * it under the terms of the GNU General Public License version 2 as
   17.10 + * published by the Free Software Foundation;
   17.11 + *
   17.12 + * This program is distributed in the hope that it will be useful,
   17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.15 + * GNU General Public License for more details.
   17.16 + *
   17.17 + * You should have received a copy of the GNU General Public License
   17.18 + * along with this program; if not, write to the Free Software
   17.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.20 + *
   17.21 + * Author: Liu Jian <liujatp@gmail.com>
   17.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   17.23 + */
   17.24 +
   17.25 +#ifndef NETLINK_MESSAGE_ROUTE_H
   17.26 +#define NETLINK_MESSAGE_ROUTE_H
   17.27 +
   17.28 +#include "ns3/object-base.h"
   17.29 +#include "ns3/address.h"
   17.30 +#include "netlink-attribute.h"
   17.31 +#include <string>
   17.32 +
   17.33 +namespace ns3 {
   17.34 +
   17.35 +/*
   17.36 +* this file define some netlink message of NETLINK_ROUTE protocol,
   17.37 +* there are mainly three types:interface address, interface info, route entry
   17.38 +* just implemented them for quagga porting.
   17.39 +*/
   17.40 +  
   17.41 +
   17.42 +
   17.43 +/**
   17.44 +* \Types of messages,here we only define the route message types quagga used
   17.45 +*/
   17.46 +enum NetlinkRtmType_e {
   17.47 +  NETLINK_RTM_BASE = 16,
   17.48 +
   17.49 +  NETLINK_RTM_NEWLINK = 16,
   17.50 +  NETLINK_RTM_DELLINK,
   17.51 +  NETLINK_RTM_GETLINK,
   17.52 +  NETLINK_RTM_SETLINK,
   17.53 +
   17.54 +  NETLINK_RTM_NEWADDR = 20,
   17.55 +  NETLINK_RTM_DELADDR,
   17.56 +  NETLINK_RTM_GETADDR,
   17.57 +
   17.58 +  NETLINK_RTM_NEWROUTE = 24,
   17.59 +  NETLINK_RTM_DELROUTE,
   17.60 +  NETLINK_RTM_GETROUTE,
   17.61 +
   17.62 +  NETLINK_RTM_MAX,
   17.63 +};  
   17.64 +
   17.65 +/**
   17.66 +* \Types of netlink groups,here we only define types quagga used
   17.67 +*/
   17.68 +enum NetlinkRtmGroup_e {
   17.69 +  NETLINK_RTM_GRP_LINK = 1,
   17.70 +  NETLINK_RTM_GRP_IPV4_IFADDR = 0x10,
   17.71 +  NETLINK_RTM_GRP_IPV4_ROUTE = 0x40,
   17.72 +  RTMGRP_IPV6_IFADDR = 0x100,
   17.73 +  RTMGRP_IPV6_ROUTE = 0x400,
   17.74 +};
   17.75 +
   17.76 +class NetlinkPayload :public ObjectBase
   17.77 +{
   17.78 +public:
   17.79 +  static TypeId GetTypeId (void);
   17.80 +  virtual TypeId GetInstanceTypeId (void) const = 0;
   17.81 +  virtual void Serialize (Buffer::Iterator& start) const = 0;
   17.82 +  virtual void Print (std::ostream &os) const = 0;
   17.83 +  virtual uint32_t GetSerializedSize (void) const = 0;
   17.84 +};
   17.85 +
   17.86 +/***
   17.87 + General form of address family dependent message.
   17.88 +
   17.89 +  struct rtgenmsg
   17.90 +  {
   17.91 +    unsigned char		rtgen_family;
   17.92 +  };
   17.93 +**/
   17.94 +
   17.95 +class GeneralMessage : public NetlinkPayload
   17.96 +{
   17.97 +public:
   17.98 +  GeneralMessage ();
   17.99 +  virtual ~GeneralMessage ();
  17.100 +
  17.101 +  static TypeId GetTypeId (void);
  17.102 +  virtual TypeId GetInstanceTypeId (void) const;
  17.103 +  virtual void Serialize (Buffer::Iterator& start) const;
  17.104 +  virtual uint32_t Deserialize (Buffer::Iterator& start);
  17.105 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  17.106 +  virtual void Print (std::ostream &os) const;
  17.107 +  virtual uint32_t GetSerializedSize (void) const;
  17.108 +
  17.109 +  
  17.110 +  virtual uint32_t GetNNetlinkAttribute (void)const;
  17.111 +  virtual NetlinkAttribute GetNetlinkAttribute (uint32_t index)const;
  17.112 +  virtual void AppendAttribute (NetlinkAttribute v);
  17.113 +  virtual void SerializeAttribute (Buffer::Iterator& start) const;
  17.114 +  virtual void PrintAttribute (std::ostream &os) const;
  17.115 +  virtual uint32_t GetAttributeSerializedSize (void) const;
  17.116 +  virtual bool GetAttributeByType (NetlinkAttribute& attr, uint16_t type);
  17.117 +
  17.118 +
  17.119 +  void SetFamily (uint8_t v);
  17.120 +  uint8_t GetFamily (void) const;
  17.121 +
  17.122 +private:
  17.123 +  static const int NETLINK_GENMSG_SIZE = 1; /* size of the struct rtgenmsg */  
  17.124 +protected:
  17.125 +  uint8_t m_family;   //always set to AF_UNSPEC
  17.126 +  //attribute can exist or not
  17.127 +  std::vector<NetlinkAttribute> m_attributes;
  17.128 +};
  17.129 +
  17.130 +
  17.131 +
  17.132 +/**
  17.133 +* \brief Link layer specific messages
  17.134 +*
  17.135 +* struct ifinfomsg
  17.136 +* passes link level specific information, not dependent
  17.137 +* on network protocol.
  17.138 +*
  17.139 +  struct ifinfomsg
  17.140 +  {
  17.141 +    unsigned char	ifi_family;
  17.142 +    unsigned char	__ifi_pad;
  17.143 +    unsigned short	ifi_type;
  17.144 +    int		ifi_index;	
  17.145 +    unsigned	ifi_flags;
  17.146 +    unsigned	ifi_change;
  17.147 +  };
  17.148 +*/
  17.149 +class InterfaceInfoMessage : public GeneralMessage
  17.150 +{
  17.151 +public:
  17.152 +  InterfaceInfoMessage ();
  17.153 +  virtual ~InterfaceInfoMessage ();
  17.154 +
  17.155 +  static TypeId GetTypeId (void);
  17.156 +  virtual TypeId GetInstanceTypeId (void) const;
  17.157 +  virtual void Serialize (Buffer::Iterator& start) const;
  17.158 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  17.159 +  virtual void Print (std::ostream &os) const;
  17.160 +  virtual uint32_t GetSerializedSize (void) const;
  17.161 +
  17.162 +  enum IflAttr_e {
  17.163 +    IFL_A_UNSPEC,
  17.164 +    IFL_A_ADDRESS,
  17.165 +    IFL_A_BROADCAST,
  17.166 +    IFL_A_IFNAME,
  17.167 +    IFL_A_MTU,
  17.168 +    IFL_A_LINK,
  17.169 +    IFL_A_QDISC,
  17.170 +    IFL_A_STATS,
  17.171 +    IFL_A_COST,
  17.172 +    IFL_A_PRIORITY,
  17.173 +    IFL_A_MASTER,
  17.174 +    IFL_A_WIRELESS,		
  17.175 +    IFL_A_PROTINFO,
  17.176 +    IFL_A_TXQLEN,
  17.177 +    IFL_A_MAP,
  17.178 +    IFL_A_WEIGHT,
  17.179 +    IFL_A_OPERSTATE,
  17.180 +    IFL_A_LINKMODE,
  17.181 +    IFL_A_MAX,
  17.182 +  };
  17.183 +
  17.184 +  enum Type_e {
  17.185 +    UP = 1,
  17.186 +    BROADCAST = 2,
  17.187 +    DBG = 4,
  17.188 +  };
  17.189 +
  17.190 +  void SetDeviceType (uint16_t type);
  17.191 +  void SetInterfaceIndex (int32_t index);
  17.192 +  void SetDeviceFlags (uint32_t index);
  17.193 +  void SetChangeMask (uint32_t mask);
  17.194 +
  17.195 +  uint16_t GetDeviceType (void) const;
  17.196 +  int32_t GetInterfaceIndex (void) const;
  17.197 +  uint32_t GetDeviceFlags (void) const;
  17.198 +  uint32_t GetChangeMask (void) const;
  17.199 +private:
  17.200 +  static const int NETLINK_INTERFACE_SIZE = 16; /* size of the struct ifinfomsg */
  17.201 +  uint8_t m_reserved; //not used
  17.202 +  uint16_t m_deviceType;
  17.203 +  int32_t m_interfaceIndex;
  17.204 +  uint32_t m_deviceFlags;
  17.205 +  uint32_t m_changeMask;
  17.206 +  NetlinkAttributeValueType m_attributeTypes[IFL_A_MAX];
  17.207 +};
  17.208 +
  17.209 +
  17.210 +
  17.211 +
  17.212 +/**
  17.213 +* \brief Interface address.
  17.214 +*
  17.215 +  struct ifaddrmsg
  17.216 +  {
  17.217 +  unsigned char	ifa_family;
  17.218 +  unsigned char	ifa_prefixlen;
  17.219 +  unsigned char	ifa_flags;
  17.220 +  unsigned char	ifa_scope;
  17.221 +  int		ifa_index;
  17.222 +  };
  17.223 +*/
  17.224 +
  17.225 +class InterfaceAddressMessage : public GeneralMessage
  17.226 +{
  17.227 +public:
  17.228 +  InterfaceAddressMessage ();
  17.229 +  virtual ~InterfaceAddressMessage ();
  17.230 +
  17.231 +  static TypeId GetTypeId (void);
  17.232 +  virtual TypeId GetInstanceTypeId (void) const;
  17.233 +  virtual void Serialize (Buffer::Iterator& start) const;
  17.234 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  17.235 +  virtual void Print (std::ostream &os) const;
  17.236 +  virtual uint32_t GetSerializedSize (void) const;
  17.237 +
  17.238 +  enum IfAttr_e {
  17.239 +    IF_A_UNSPEC,
  17.240 +    IF_A_ADDRESS,
  17.241 +    IF_A_LOCAL,
  17.242 +    IF_A_LABEL,
  17.243 +    IF_A_BROADCAST,
  17.244 +    IF_A_ANYCAST,
  17.245 +    IF_A_CACHEINFO,
  17.246 +    IF_A_MULTICAST,
  17.247 +    IF_A_MAX
  17.248 +  };
  17.249 +
  17.250 +  enum {
  17.251 +    F_SECONDARY = 0x01,
  17.252 +    F_PERMANENT = 0x80,
  17.253 +    F_DEPRECATED = 0x20,
  17.254 +    F_TENTATIVE = 0x40
  17.255 +  };
  17.256 +  enum {
  17.257 +    SCOPE_UNIVERSE = 0,
  17.258 +    SCOPE_SITE = 200,
  17.259 +    SCOPE_LINK = 253,
  17.260 +    SCOPE_HOST = 254
  17.261 +  };
  17.262 +
  17.263 +
  17.264 +  void SetFamily (uint8_t family);
  17.265 +  void SetLength (uint8_t length);
  17.266 +  void SetFlags (uint8_t flags);
  17.267 +  void SetScope (uint8_t scope);
  17.268 +  void SetInterfaceIndex (int32_t index);
  17.269 +
  17.270 +  uint8_t GetFamily (void) const;
  17.271 +  uint8_t GetLength (void) const;
  17.272 +  uint8_t GetFlags (void) const;
  17.273 +  uint8_t GetScope (void) const;
  17.274 +  int32_t GetInterfaceIndex (void) const;
  17.275 +
  17.276 +private:
  17.277 +  static const int NETLINK_ADDRESS_SIZE = 8; /* size of the struct ifaddrmsg */
  17.278 +  uint8_t m_length;
  17.279 +  uint8_t m_flags;
  17.280 +  uint8_t m_scope;
  17.281 +  int32_t m_index;
  17.282 +  NetlinkAttributeValueType m_attributeTypes[IF_A_MAX];
  17.283 +};
  17.284 +
  17.285 +
  17.286 +/**
  17.287 +* \brief Definitions used in routing table administration.
  17.288 +*
  17.289 +  struct rtmsg
  17.290 +  {
  17.291 +    unsigned char		rtm_family;
  17.292 +    unsigned char		rtm_dst_len;
  17.293 +    unsigned char		rtm_src_len;
  17.294 +    unsigned char		rtm_tos;
  17.295 +
  17.296 +    unsigned char		rtm_table;	// Routing table id 
  17.297 +    unsigned char		rtm_protocol;	//Routing protocol; 
  17.298 +    unsigned char		rtm_scope;	
  17.299 +    unsigned char		rtm_type;	
  17.300 +
  17.301 +    unsigned		rtm_flags;
  17.302 +  };
  17.303 +*/
  17.304 +
  17.305 +class RouteMessage : public GeneralMessage
  17.306 +{
  17.307 +public:
  17.308 +  RouteMessage ();
  17.309 +  virtual ~RouteMessage ();
  17.310 +
  17.311 +  static TypeId GetTypeId (void);
  17.312 +  virtual TypeId GetInstanceTypeId (void) const;
  17.313 +  virtual void Serialize (Buffer::Iterator& start) const;
  17.314 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  17.315 +  virtual void Print (std::ostream &os) const;
  17.316 +  virtual uint32_t GetSerializedSize (void) const;
  17.317 +
  17.318 +  uint8_t GetFamily (void) const;
  17.319 +  uint8_t GetDstLength (void) const;
  17.320 +  uint8_t GetSrcLength (void) const;
  17.321 +  uint8_t GetTos (void) const;
  17.322 +  uint8_t GetTableId (void) const;
  17.323 +  uint8_t GetProtocol(void) const;
  17.324 +  uint8_t GetType (void) const;
  17.325 +  uint8_t GetScope (void) const;
  17.326 +  uint32_t GetFlags (void) const;
  17.327 +  void SetFamily (uint8_t v);
  17.328 +  void SetDstLength (uint8_t v);
  17.329 +  void SetSrcLength (uint8_t v);
  17.330 +  void SetTos (uint8_t v);
  17.331 +  void SetTableId (uint8_t v);
  17.332 +  void SetProtocol (uint8_t v);
  17.333 +  void SetScope (uint8_t v);
  17.334 +  void SetType (uint8_t v);
  17.335 +  void SetFlags (uint32_t v);
  17.336 +
  17.337 +  enum RtProtocol_e {
  17.338 +    RT_PROT_UNSPEC = 0,
  17.339 +  };
  17.340 +
  17.341 +  enum RtFlags_e {
  17.342 +    RT_F_CLONED = 0x200,
  17.343 +  };
  17.344 +
  17.345 +  enum RtScope_e {
  17.346 +    RT_SCOPE_UNIVERSE = 0,
  17.347 +    RT_SCOPE_LINK = 253,
  17.348 +  };
  17.349 +
  17.350 +  enum RtClass_e {
  17.351 +    RT_TABLE_UNSPEC = 0,
  17.352 +    RT_TABLE_MAIN = 254,
  17.353 +  };
  17.354 +
  17.355 +  enum RtAttr_e {
  17.356 +    RT_A_UNSPEC,
  17.357 +    RT_A_DST,
  17.358 +    RT_A_SRC,
  17.359 +    RT_A_IIF,
  17.360 +    RT_A_OIF,
  17.361 +    RT_A_GATEWAY,
  17.362 +    RT_A_PRIORITY,
  17.363 +    RT_A_PREFSRC,
  17.364 +    RT_A_METRICS,
  17.365 +    RT_A_MULTIPATH,
  17.366 +    RT_A_PROTOINFO,
  17.367 +    RT_A_FLOW,
  17.368 +    RT_A_CACHEINFO,
  17.369 +    RT_A_SESSION,
  17.370 +    RT_A_MP_ALGO,
  17.371 +    RT_A_TABLE,
  17.372 +    RT_A_MAX
  17.373 +  };
  17.374 +
  17.375 +
  17.376 +private:
  17.377 +  static const int NETLINK_ROUTE_SIZE = 12; /* size of the struct rtmsg */
  17.378 +  uint8_t m_dstLen;
  17.379 +  uint8_t m_srcLen;
  17.380 +  uint8_t m_tos;
  17.381 +  uint8_t m_tableId;
  17.382 +  uint8_t m_protocol;
  17.383 +  uint8_t m_scope;
  17.384 +  uint8_t m_type;
  17.385 +  uint32_t m_flags;
  17.386 +  NetlinkAttributeValueType m_attributeTypes[RT_A_MAX];
  17.387 +};
  17.388 +
  17.389 +}; // namespace ns3
  17.390 +
  17.391 +#endif /* NETLINK_MESSAGE_ROUTE_H */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/model/netlink-message.cc	Mon Apr 18 12:13:02 2011 +0200
    18.3 @@ -0,0 +1,672 @@
    18.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    18.5 +/*
    18.6 + * Copyright (c) 2008 Liu Jian
    18.7 + *
    18.8 + * This program is free software; you can redistribute it and/or modify
    18.9 + * it under the terms of the GNU General Public License version 2 as
   18.10 + * published by the Free Software Foundation;
   18.11 + *
   18.12 + * This program is distributed in the hope that it will be useful,
   18.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.15 + * GNU General Public License for more details.
   18.16 + *
   18.17 + * You should have received a copy of the GNU General Public License
   18.18 + * along with this program; if not, write to the Free Software
   18.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.20 + *
   18.21 + * Author: Liu Jian <liujatp@gmail.com>
   18.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   18.23 + */
   18.24 +
   18.25 +#include "netlink-message.h"
   18.26 +#include "ns3/address-utils.h"
   18.27 +#include "ns3/log.h"
   18.28 +
   18.29 +NS_LOG_COMPONENT_DEFINE ("NetlinkMessage");
   18.30 +
   18.31 +namespace ns3 {
   18.32 +
   18.33 +/***********************************************************************************
   18.34 +* \ NetlinkMessageHeader
   18.35 +***********************************************************************************/
   18.36 +NS_OBJECT_ENSURE_REGISTERED (NetlinkMessageHeader);
   18.37 +NS_OBJECT_ENSURE_REGISTERED (NetlinkMessage);
   18.38 +
   18.39 +NetlinkMessageHeader::NetlinkMessageHeader ()
   18.40 +  : m_nlmsgLen (16),
   18.41 +    m_nlmsgType (0),
   18.42 +    m_nlmsgFlags (0),
   18.43 +    m_nlmsgSeq (0),
   18.44 +    m_nlmsgPid (0)
   18.45 +{}
   18.46 +
   18.47 +NetlinkMessageHeader::NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid)
   18.48 +  : m_nlmsgLen (16),
   18.49 +    m_nlmsgType (type),
   18.50 +    m_nlmsgFlags (flags),
   18.51 +    m_nlmsgSeq (seq),
   18.52 +    m_nlmsgPid (pid)
   18.53 +{}
   18.54 +
   18.55 +void
   18.56 +NetlinkMessageHeader::SetMsgLen (uint32_t v)
   18.57 +{
   18.58 +  m_nlmsgLen = v;
   18.59 +}
   18.60 +void
   18.61 +NetlinkMessageHeader::SetMsgFlags (uint16_t v)
   18.62 +{
   18.63 +  m_nlmsgFlags = v;
   18.64 +}
   18.65 +void
   18.66 +NetlinkMessageHeader::SetMsgType (uint16_t v)
   18.67 +{
   18.68 +  m_nlmsgType = v;
   18.69 +}
   18.70 +void
   18.71 +NetlinkMessageHeader::SetMsgSeq (uint32_t v)
   18.72 +{
   18.73 +  m_nlmsgSeq = v;
   18.74 +}
   18.75 +void
   18.76 +NetlinkMessageHeader::SetMsgPid (uint32_t v)
   18.77 +{
   18.78 +  m_nlmsgPid = v;
   18.79 +}
   18.80 +uint16_t
   18.81 +NetlinkMessageHeader::GetMsgFlags (void) const
   18.82 +{
   18.83 +  return m_nlmsgFlags;
   18.84 +}
   18.85 +uint32_t 
   18.86 +NetlinkMessageHeader::GetMsgLen (void) const
   18.87 +{
   18.88 +  return m_nlmsgLen;
   18.89 +}
   18.90 +uint16_t 
   18.91 +NetlinkMessageHeader::GetMsgType (void) const
   18.92 +{
   18.93 +  return m_nlmsgType;
   18.94 +}
   18.95 +uint32_t
   18.96 +NetlinkMessageHeader::GetMsgSeq (void) const
   18.97 +{
   18.98 +  return m_nlmsgSeq;
   18.99 +}
  18.100 +uint32_t 
  18.101 +NetlinkMessageHeader::GetMsgPid (void) const
  18.102 +{
  18.103 +  return m_nlmsgPid;
  18.104 +}
  18.105 +uint32_t
  18.106 +NetlinkMessageHeader::GetHeaderSize ()
  18.107 +{
  18.108 +  return NETLINK_MSG_HEADER_SIZE;
  18.109 +}
  18.110 +uint32_t
  18.111 +NetlinkMessageHeader::GetPayloadSize (void) const
  18.112 +{
  18.113 +  return NETLINK_MSG_ALIGN (m_nlmsgLen - NETLINK_MSG_HEADER_SIZE);
  18.114 +}
  18.115 +
  18.116 +TypeId 
  18.117 +NetlinkMessageHeader::GetTypeId (void)
  18.118 +{
  18.119 +  static TypeId tid = TypeId ("ns3::NetlinkMessageHeader")
  18.120 +    .SetParent<Header> ()
  18.121 +    .AddConstructor<NetlinkMessageHeader> ()
  18.122 +    ;
  18.123 +  return tid;
  18.124 +}
  18.125 +TypeId 
  18.126 +NetlinkMessageHeader::GetInstanceTypeId (void) const
  18.127 +{
  18.128 +  return GetTypeId ();
  18.129 +}
  18.130 +void 
  18.131 +NetlinkMessageHeader::Print (std::ostream &os) const
  18.132 +{
  18.133 +  os << "NetlinkMessageHeader "
  18.134 +     << "len: " << m_nlmsgLen << " "
  18.135 +     << "flags: " << m_nlmsgFlags << " "
  18.136 +     << "type: " << m_nlmsgType << " "
  18.137 +     << "seq: " << m_nlmsgSeq << " "
  18.138 +     << "pid: " << m_nlmsgPid;
  18.139 +}
  18.140 +
  18.141 +uint32_t 
  18.142 +NetlinkMessageHeader::GetSerializedSize (void) const
  18.143 +{
  18.144 +  /* this is the size of an nlmsghdr payload. */
  18.145 +  return NETLINK_MSG_HEADER_SIZE;
  18.146 +}
  18.147 +
  18.148 +void
  18.149 +NetlinkMessageHeader::Serialize (Buffer::Iterator& start) const
  18.150 +{
  18.151 +  start.WriteU32 (m_nlmsgLen);
  18.152 +  start.WriteU16 (m_nlmsgType);
  18.153 +  start.WriteU16 (m_nlmsgFlags);
  18.154 +  start.WriteU32 (m_nlmsgSeq);
  18.155 +  start.WriteU32 (m_nlmsgPid);
  18.156 +}
  18.157 +
  18.158 +uint32_t
  18.159 +NetlinkMessageHeader::Deserialize (Buffer::Iterator& start)
  18.160 +{
  18.161 +  m_nlmsgLen = start.ReadU32 ();
  18.162 +  m_nlmsgType = start.ReadU16 ();
  18.163 +  m_nlmsgFlags = start.ReadU16 ();
  18.164 +  m_nlmsgSeq = start.ReadU32 ();
  18.165 +  m_nlmsgPid = start.ReadU32 ();
  18.166 +
  18.167 +  return GetSerializedSize ();
  18.168 +}
  18.169 +
  18.170 +
  18.171 +
  18.172 +
  18.173 +/***********************************************************************************
  18.174 +* \ NetlinkMessageError
  18.175 +***********************************************************************************/
  18.176 +
  18.177 +NetlinkMessageError::NetlinkMessageError ()
  18.178 +  : m_error (0)
  18.179 +{
  18.180 +}
  18.181 +NetlinkMessageError::~NetlinkMessageError ()
  18.182 +{}
  18.183 +void 
  18.184 +NetlinkMessageError::SetError (int32_t v)
  18.185 +{
  18.186 +  m_error = v;
  18.187 +}
  18.188 +int32_t
  18.189 +NetlinkMessageError::GetError (void) const
  18.190 +{
  18.191 +  return m_error;
  18.192 +}
  18.193 +void
  18.194 +NetlinkMessageError::SetMsg (NetlinkMessageHeader v)
  18.195 +{
  18.196 +  m_msg = v;
  18.197 +}
  18.198 +NetlinkMessageHeader
  18.199 +NetlinkMessageError::GetMsg (void) const
  18.200 +{
  18.201 +  return m_msg;
  18.202 +}
  18.203 +
  18.204 +TypeId 
  18.205 +NetlinkMessageError::GetTypeId (void)
  18.206 +{
  18.207 +  static TypeId tid = TypeId ("ns3::NetlinkMessageError")
  18.208 +    .SetParent<NetlinkPayload> ()
  18.209 +    .AddConstructor<NetlinkMessageError> ()
  18.210 +    ;
  18.211 +  return tid;
  18.212 +}
  18.213 +
  18.214 +TypeId 
  18.215 +NetlinkMessageError::GetInstanceTypeId (void) const
  18.216 +{
  18.217 +  return GetTypeId ();
  18.218 +}
  18.219 +void 
  18.220 +NetlinkMessageError::Print (std::ostream &os) const
  18.221 +{  
  18.222 +  os << "----NetlinkMessageError "
  18.223 +     << "error: " << m_error << " "
  18.224 +     << "msg:( ";
  18.225 +  m_msg.Print(os);
  18.226 +  os << " )";
  18.227 +}
  18.228 +
  18.229 +uint32_t 
  18.230 +NetlinkMessageError::GetSerializedSize (void) const
  18.231 +{
  18.232 +  /* this is the size of an nlmsgerr payload. */
  18.233 +  return NETLINK_MSG_ERROR_SIZE;
  18.234 +}
  18.235 +
  18.236 +void
  18.237 +NetlinkMessageError::Serialize (Buffer::Iterator& start) const
  18.238 +{
  18.239 +  start.WriteU32 (m_error);
  18.240 +  m_msg.Serialize (start);
  18.241 +}
  18.242 +
  18.243 +uint32_t
  18.244 +NetlinkMessageError::Deserialize (Buffer::Iterator& start)
  18.245 +{  
  18.246 +  m_error = start.ReadU32 ();
  18.247 +  m_msg.Deserialize (start);
  18.248 +  
  18.249 +  return GetSerializedSize ();
  18.250 +}
  18.251 +
  18.252 +
  18.253 +
  18.254 +
  18.255 +/***********************************************************************************
  18.256 +* \ NetlinkMessage
  18.257 +***********************************************************************************/
  18.258 +NetlinkMessage::NetlinkMessage ()
  18.259 +{}
  18.260 +
  18.261 +void
  18.262 +NetlinkMessage::SetHeader (NetlinkMessageHeader hdr)
  18.263 +{
  18.264 +  m_hdr = hdr;
  18.265 +}
  18.266 +NetlinkMessageHeader
  18.267 +NetlinkMessage::GetHeader (void)const
  18.268 +{
  18.269 +  return m_hdr;
  18.270 +}
  18.271 +void
  18.272 +NetlinkMessage::SetGeneralMessage (GeneralMessage genmsg)
  18.273 +{
  18.274 +  m_genmsg = genmsg;
  18.275 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + genmsg.GetSerializedSize ());
  18.276 +}
  18.277 +void
  18.278 +NetlinkMessage::SetErrorMessage (NetlinkMessageError errmsg)
  18.279 +{
  18.280 +  m_errorMessage = errmsg;
  18.281 +  m_hdr.SetMsgLen(m_hdr.GetSerializedSize () + errmsg.GetSerializedSize ());
  18.282 +}
  18.283 +// the type is one of RTM_NEWLINK,RTM_DELLINK,RTM_GETLINK
  18.284 +void
  18.285 +NetlinkMessage::SetInterfaceInfoMessage (InterfaceInfoMessage v)
  18.286 +{
  18.287 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  18.288 +  m_interfaceTemplate = v;
  18.289 +}
  18.290 +// the type is one of RTM_NEWADDR,RTM_DELADDR,RTM_GETADDR
  18.291 +void NetlinkMessage::SetInterfaceAddressMessage (InterfaceAddressMessage v)
  18.292 +{
  18.293 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  18.294 +  m_addressTemplate = v;
  18.295 +}
  18.296 +// the type  is one of RTM_NEWROUTE,RTM_DELROUTE,RTM_GETROUTE
  18.297 +void NetlinkMessage::SetRouteMessage (RouteMessage v)
  18.298 +{
  18.299 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  18.300 +  m_routeTemplate = v;
  18.301 +}
  18.302 +GeneralMessage
  18.303 +NetlinkMessage::GetGeneralMessage (void) const
  18.304 +{
  18.305 +  return m_genmsg;
  18.306 +}
  18.307 +NetlinkMessageError
  18.308 +NetlinkMessage::GetErrorMessage (void) const
  18.309 +{
  18.310 +  return m_errorMessage;
  18.311 +}
  18.312 +InterfaceInfoMessage
  18.313 +NetlinkMessage::GetInterfaceInfoMessage (void) const
  18.314 +{
  18.315 +  return m_interfaceTemplate;
  18.316 +}
  18.317 +InterfaceAddressMessage
  18.318 +NetlinkMessage::GetInterfaceAddressMessage (void) const
  18.319 +{
  18.320 +  return m_addressTemplate;
  18.321 +}
  18.322 +RouteMessage
  18.323 +NetlinkMessage::GetRouteMessage (void) const
  18.324 +{
  18.325 +  return m_routeTemplate;
  18.326 +}
  18.327 +bool
  18.328 +NetlinkMessage::IsMessageNetlinkControl (uint16_t type)
  18.329 +{
  18.330 +  return (type < NETLINK_RTM_BASE);
  18.331 +}
  18.332 +bool
  18.333 +NetlinkMessage::IsMessageNetlinkRoute (uint16_t type)
  18.334 +{
  18.335 +  return (type >= NETLINK_RTM_BASE && type < NETLINK_RTM_MAX);
  18.336 +}
  18.337 +bool
  18.338 +NetlinkMessage::IsMessageAddress (uint16_t type)
  18.339 +{
  18.340 +  return (type >= NETLINK_RTM_NEWADDR && type <= NETLINK_RTM_GETADDR);
  18.341 +}
  18.342 +bool
  18.343 +NetlinkMessage::IsMessageInterface (uint16_t type)
  18.344 +{
  18.345 +  return (type >= NETLINK_RTM_NEWLINK && type <= NETLINK_RTM_SETLINK);
  18.346 +}
  18.347 +bool
  18.348 +NetlinkMessage::IsMessageRoute (uint16_t type)
  18.349 +{
  18.350 +  return (type >= NETLINK_RTM_NEWROUTE && type <= NETLINK_RTM_GETROUTE);
  18.351 +}
  18.352 +bool
  18.353 +NetlinkMessage::IsMessageTypeGet (uint16_t type)
  18.354 +{
  18.355 +  return ((( type - NETLINK_RTM_BASE)&3) == 2);
  18.356 +}
  18.357 +bool
  18.358 +NetlinkMessage::IsMessageFlagsAck (uint16_t flags)
  18.359 +{
  18.360 +  return (flags & NETLINK_MSG_F_ACK) ? true : false;
  18.361 +}
  18.362 +bool
  18.363 +NetlinkMessage::IsMessageFlagsRequest (uint16_t flags)
  18.364 +{
  18.365 +  return (flags & NETLINK_MSG_F_REQUEST) ? true : false;
  18.366 +}
  18.367 +bool
  18.368 +NetlinkMessage::IsMessageFlagsDump (uint16_t flags)
  18.369 +{
  18.370 +  return (flags & NETLINK_MSG_F_DUMP) ? true : false;
  18.371 +}
  18.372 +
  18.373 +NetlinkMessage::operator MultipartNetlinkMessage (void) const
  18.374 +{
  18.375 +  MultipartNetlinkMessage multi_nlmsg;
  18.376 +  multi_nlmsg.AppendMessage (*this);
  18.377 +  return multi_nlmsg;
  18.378 +}
  18.379 +
  18.380 +TypeId 
  18.381 +NetlinkMessage::GetTypeId (void)
  18.382 +{
  18.383 +  static TypeId tid = TypeId ("ns3::NetlinkMessage")
  18.384 +    .SetParent<Header> ()
  18.385 +    .AddConstructor<NetlinkMessage> ()
  18.386 +    ;
  18.387 +  return tid;
  18.388 +}
  18.389 +TypeId 
  18.390 +NetlinkMessage::GetInstanceTypeId (void) const
  18.391 +{
  18.392 +  return GetTypeId ();
  18.393 +}
  18.394 +
  18.395 +uint32_t
  18.396 +NetlinkMessage::GetTotalSize (void) const
  18.397 +{
  18.398 +  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
  18.399 +}
  18.400 +
  18.401 +uint32_t
  18.402 +NetlinkMessage::GetMsgSize (void) const
  18.403 +{
  18.404 +  return m_hdr.GetMsgLen ();
  18.405 +}
  18.406 +
  18.407 +uint32_t
  18.408 +NetlinkMessage::GetPayloadSize (void) const
  18.409 +{
  18.410 +  return m_hdr.GetPayloadSize ();
  18.411 +}
  18.412 +uint16_t
  18.413 +NetlinkMessage::GetMsgType (void) const
  18.414 +{
  18.415 +  return m_hdr.GetMsgType ();
  18.416 +}
  18.417 +
  18.418 +uint8_t
  18.419 +NetlinkMessage::GetFamily(void) const
  18.420 +{
  18.421 +  if (IsMessageTypeGet (GetMsgType ()))
  18.422 +    {
  18.423 +      NS_LOG_DEBUG ("TypeGetMsg");
  18.424 +    }
  18.425 +  if (IsMessageAddress (m_hdr.GetMsgType ()))
  18.426 +    {
  18.427 +      return m_addressTemplate.GetFamily ();
  18.428 +    }
  18.429 +  else if (IsMessageInterface(m_hdr.GetMsgType ()))
  18.430 +    {
  18.431 +      return m_interfaceTemplate.GetFamily ();
  18.432 +    }
  18.433 +  else if (IsMessageRoute(m_hdr.GetMsgType ()))
  18.434 +    {
  18.435 +      return m_routeTemplate.GetFamily ();
  18.436 +    }
  18.437 +  else if (IsMessageFlagsDump (m_hdr.GetMsgFlags ()))
  18.438 +    {
  18.439 +      return m_genmsg.GetFamily (); //value is said to be always set to AF_UNSPEC
  18.440 +    }
  18.441 +  else
  18.442 +    {
  18.443 +      NS_LOG_WARN ("Netlink message type not supported, return AF_UNSPEC");
  18.444 +      return 0;
  18.445 +    }
  18.446 +}
  18.447 +
  18.448 +void 
  18.449 +NetlinkMessage::Print (std::ostream &os) const
  18.450 +{
  18.451 +  uint16_t type = m_hdr.GetMsgType ();
  18.452 +
  18.453 +  os << "NetlinkMessage  ";
  18.454 +  os << " ----Header:(";
  18.455 +  m_hdr.Print(os);
  18.456 +  os << ")";
  18.457 +
  18.458 +  if (type == NETLINK_MSG_DONE )
  18.459 +    {
  18.460 +      os << "multipart message ends here";
  18.461 +    }
  18.462 +  else if (type == NETLINK_MSG_ERROR )
  18.463 +    {
  18.464 +      m_errorMessage.Print (os);
  18.465 +    }
  18.466 +  else if (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK)
  18.467 +    {
  18.468 +      m_genmsg.Print (os);
  18.469 +    }  
  18.470 +  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE)
  18.471 +    {
  18.472 +      m_routeTemplate.Print (os);
  18.473 +    }
  18.474 +  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  18.475 +    {
  18.476 +      m_addressTemplate.Print (os);
  18.477 +    }
  18.478 +  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_DELLINK)
  18.479 +    {
  18.480 +      m_interfaceTemplate.Print (os);
  18.481 +    }
  18.482 +  else
  18.483 +    {
  18.484 +      os << "service not supported yet( " << type <<")";
  18.485 +    }
  18.486 +}
  18.487 +uint32_t 
  18.488 +NetlinkMessage::GetSerializedSize (void) const
  18.489 +{
  18.490 +  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
  18.491 +}
  18.492 +
  18.493 +void
  18.494 +NetlinkMessage::Serialize (Buffer::Iterator& start) const
  18.495 +{
  18.496 +  NS_LOG_FUNCTION (this);
  18.497 +  //  Print (std::cout);
  18.498 +  uint16_t type = m_hdr.GetMsgType ();
  18.499 +
  18.500 +  m_hdr.Serialize (start);
  18.501 +
  18.502 +  if (type == NETLINK_MSG_DONE)
  18.503 +    {
  18.504 +      //nothing done
  18.505 +    }
  18.506 +  else if (type == NETLINK_MSG_ERROR)
  18.507 +    {
  18.508 +      m_errorMessage.Serialize (start);
  18.509 +    }  
  18.510 +  else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags ()) && 
  18.511 +           (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
  18.512 +    {
  18.513 +      m_genmsg.Serialize (start);
  18.514 +    }  
  18.515 +  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  18.516 +    {
  18.517 +      m_routeTemplate.Serialize (start);
  18.518 +    }
  18.519 +  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  18.520 +    {
  18.521 +      m_addressTemplate.Serialize (start);
  18.522 +    }
  18.523 +  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
  18.524 +    {
  18.525 +      m_interfaceTemplate.Serialize (start);
  18.526 +    }
  18.527 +  else
  18.528 +    {
  18.529 +    }  
  18.530 +}
  18.531 +
  18.532 +
  18.533 +uint32_t
  18.534 +NetlinkMessage::Deserialize (Buffer::Iterator&start)
  18.535 +{
  18.536 +  uint32_t remaining;
  18.537 +
  18.538 +  m_hdr.Deserialize (start);
  18.539 +  remaining = NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ()) - m_hdr.GetSerializedSize ();
  18.540 +  
  18.541 +  //Deserialize service module
  18.542 +  uint16_t type = GetMsgType ();
  18.543 +  if (remaining)
  18.544 +    {        
  18.545 +      if (type == NETLINK_MSG_DONE)
  18.546 +        {
  18.547 +          //do nothing
  18.548 +        }
  18.549 +      else if (type == NETLINK_MSG_ERROR)
  18.550 +        {
  18.551 +          remaining -= m_errorMessage.Deserialize (start);
  18.552 +        }      
  18.553 +      else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags()) &&
  18.554 +               (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
  18.555 +        {
  18.556 +          remaining -= m_genmsg.Deserialize (start, remaining);
  18.557 +        }
  18.558 +      else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  18.559 +        {
  18.560 +          remaining -= m_routeTemplate.Deserialize (start, remaining);
  18.561 +        }
  18.562 +      else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  18.563 +        {
  18.564 +          remaining -= m_addressTemplate.Deserialize (start, remaining);
  18.565 +        }
  18.566 +      else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
  18.567 +        {
  18.568 +          remaining -= m_interfaceTemplate.Deserialize (start, remaining);
  18.569 +        }
  18.570 +      else
  18.571 +        {
  18.572 +          //do nothing
  18.573 +        }
  18.574 +    }
  18.575 +
  18.576 +  return GetSerializedSize ();
  18.577 +}
  18.578 +
  18.579 +
  18.580 +/***********************************************************************************
  18.581 +* \ MultipartNetlinkMessage
  18.582 +***********************************************************************************/
  18.583 +MultipartNetlinkMessage::MultipartNetlinkMessage ()
  18.584 +{}
  18.585 +
  18.586 +TypeId 
  18.587 +MultipartNetlinkMessage::GetTypeId (void)
  18.588 +{
  18.589 +  static TypeId tid = TypeId ("ns3::MultipartNetlinkMessage")
  18.590 +    .SetParent<Header> ()
  18.591 +    .AddConstructor<MultipartNetlinkMessage> ()
  18.592 +    ;
  18.593 +  return tid;
  18.594 +}
  18.595 +TypeId 
  18.596 +MultipartNetlinkMessage::GetInstanceTypeId (void) const
  18.597 +{
  18.598 +  return GetTypeId ();
  18.599 +}
  18.600 +
  18.601 +void
  18.602 +MultipartNetlinkMessage::Print (std::ostream &os) const
  18.603 +{
  18.604 +  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  18.605 +    {
  18.606 +      m_netlinkMessages[i].Print (os);
  18.607 +    }
  18.608 +}
  18.609 +uint32_t
  18.610 +MultipartNetlinkMessage::GetSerializedSize (void) const
  18.611 +{
  18.612 +  uint32_t len = 0;
  18.613 +
  18.614 +  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  18.615 +    {
  18.616 +      len +=  m_netlinkMessages[i].GetSerializedSize ();
  18.617 +    }
  18.618 +  return len;
  18.619 +}
  18.620 +void
  18.621 +MultipartNetlinkMessage::Serialize (Buffer::Iterator start) const
  18.622 +{
  18.623 +  NS_LOG_FUNCTION ("Multi" << this);
  18.624 +  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  18.625 +    {
  18.626 +      m_netlinkMessages[i].Serialize (start);
  18.627 +    }
  18.628 +}
  18.629 +uint32_t
  18.630 +MultipartNetlinkMessage::Deserialize (Buffer::Iterator start)
  18.631 +{
  18.632 +  while (1)
  18.633 +    {
  18.634 +      NetlinkMessage nlmsg;
  18.635 +      nlmsg.Deserialize (start);
  18.636 +      AppendMessage (nlmsg);
  18.637 +
  18.638 +      if (!(nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_MULTI))
  18.639 +        {
  18.640 +          break;
  18.641 +        }
  18.642 +
  18.643 +      if (nlmsg.GetHeader ().GetMsgType() == NETLINK_MSG_DONE)
  18.644 +        {
  18.645 +          break;
  18.646 +        }
  18.647 +    }
  18.648 +  return GetSerializedSize ();
  18.649 +}
  18.650 +
  18.651 +void
  18.652 +MultipartNetlinkMessage::AppendMessage (NetlinkMessage nlmsg)
  18.653 +{
  18.654 +  m_netlinkMessages.push_back (nlmsg);
  18.655 +}
  18.656 +
  18.657 +void
  18.658 +MultipartNetlinkMessage::Clear ()
  18.659 +{
  18.660 +  m_netlinkMessages.clear ();
  18.661 +}
  18.662 +
  18.663 +uint32_t
  18.664 +MultipartNetlinkMessage::GetNMessages (void) const
  18.665 +{
  18.666 +  return m_netlinkMessages.size ();
  18.667 +}
  18.668 +NetlinkMessage
  18.669 +MultipartNetlinkMessage::GetMessage (uint32_t index) const
  18.670 +{
  18.671 +  NS_ASSERT(index < m_netlinkMessages.size ());
  18.672 +  return m_netlinkMessages[index];
  18.673 +}
  18.674 +
  18.675 +}; // namespace ns3
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/model/netlink-message.h	Mon Apr 18 12:13:02 2011 +0200
    19.3 @@ -0,0 +1,256 @@
    19.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    19.5 +/*
    19.6 + * Copyright (c) 2008 Liu Jian
    19.7 + *
    19.8 + * This program is free software; you can redistribute it and/or modify
    19.9 + * it under the terms of the GNU General Public License version 2 as
   19.10 + * published by the Free Software Foundation;
   19.11 + *
   19.12 + * This program is distributed in the hope that it will be useful,
   19.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.15 + * GNU General Public License for more details.
   19.16 + *
   19.17 + * You should have received a copy of the GNU General Public License
   19.18 + * along with this program; if not, write to the Free Software
   19.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.20 + *
   19.21 + * Author: Liu Jian <liujatp@gmail.com>
   19.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   19.23 + */
   19.24 +
   19.25 +#ifndef NETLINK_MESSAGE_H
   19.26 +#define NETLINK_MESSAGE_H
   19.27 +
   19.28 +#include "ns3/header.h"
   19.29 +#include "ns3/address.h"
   19.30 +#include "netlink-message-route.h"
   19.31 +#include "netlink-attribute.h"
   19.32 +
   19.33 +
   19.34 +namespace ns3 {
   19.35 +  class NetlinkPayload;
   19.36 +  class GeneralMessage;
   19.37 +  class InterfaceAddressMessage;
   19.38 +  class InterfaceInfoMessage;
   19.39 +  class RouteMessage;
   19.40 +  class MultipartNetlinkMessage;
   19.41 +
   19.42 +/**
   19.43 +* \brief The Netlink message structure for an netlink packet
   19.44 +* 
   19.45 +There are three levels to a Netlink message: The general Netlink
   19.46 +message header, the IP service specific template, and the IP service
   19.47 +specific data.
   19.48 +
   19.49 +0                   1                   2                   3
   19.50 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   19.51 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   19.52 +|                                                               |
   19.53 +|                   Netlink message header                      |
   19.54 +|                                                               |
   19.55 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   19.56 +|                                                               |
   19.57 +|                  IP Service Template                          |
   19.58 +|                                                               |
   19.59 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   19.60 +|                                                               |
   19.61 +|                  IP Service specific data in TLVs             |
   19.62 +|                                                               |
   19.63 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   19.64 +*/
   19.65 +
   19.66 +  enum NetlinkMessageFlag
   19.67 +  {
   19.68 +    NETLINK_MSG_F_REQUEST = 1,  // It is request message.
   19.69 +    NETLINK_MSG_F_MULTI = 2,    // Multipart message, terminated by NETLINK_MSG_DONE
   19.70 +    NETLINK_MSG_F_ACK = 4,      // Reply with ack, with zero or error code
   19.71 +    NETLINK_MSG_F_ECHO = 8,     // Echo this request 
   19.72 +
   19.73 +    /* Modifiers to Get request */
   19.74 +    NETLINK_MSG_F_ROOT = 0x100,        // specify tree root
   19.75 +    NETLINK_MSG_F_MATCH = 0x200,       // return all matching
   19.76 +    NETLINK_MSG_F_ATOMIC = 0x400,      // atomic Get =
   19.77 +    NETLINK_MSG_F_DUMP = (NETLINK_MSG_F_ROOT|NETLINK_MSG_F_MATCH),
   19.78 +
   19.79 +    /* Modifiers to NEW request */
   19.80 +    NETLINK_MSG_F_REPLACE = 0x100, // Override existing = 
   19.81 +    NETLINK_MSG_F_EXCL = 0x200,   // Do not touch, if it exists
   19.82 +    NETLINK_MSG_F_CREATE = 0x400,  // Create, if it does not exist
   19.83 +    NETLINK_MSG_F_APPEND = 0x800,  // Add to end of list = 
   19.84 +  };
   19.85 +
   19.86 +  enum NetlinkMessageType
   19.87 +  {
   19.88 +    NETLINK_MSG_NOOP = 0x1,          // Nothing.
   19.89 +    NETLINK_MSG_ERROR = 0x2,         // Error
   19.90 +    NETLINK_MSG_DONE = 0x3,          // End of a dump
   19.91 +    NETLINK_MSG_OVERRUN = 0x4,       // Data lost
   19.92 +    NETLINK_MSG_MIN_TYPE = 0x10,     // < 0x10: reserved control messages
   19.93 +  };
   19.94 +
   19.95 +#define NETLINK_MSG_ALIGNTO 4
   19.96 +#define NETLINK_MSG_ALIGN(X)    (((X)+NETLINK_MSG_ALIGNTO-1) & ~(NETLINK_MSG_ALIGNTO-1) )
   19.97 +
   19.98 +class NetlinkMessageHeader : public ObjectBase
   19.99 +{
  19.100 +public:
  19.101 +  NetlinkMessageHeader ();
  19.102 +  NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid);
  19.103 +
  19.104 +  static TypeId GetTypeId (void);
  19.105 +  virtual TypeId GetInstanceTypeId (void) const;
  19.106 +  void Print (std::ostream &os) const;
  19.107 +  uint32_t GetSerializedSize (void) const;
  19.108 +  void Serialize (Buffer::Iterator& start) const;
  19.109 +  uint32_t Deserialize (Buffer::Iterator& start);
  19.110 +
  19.111 +  void SetMsgLen (uint32_t v);
  19.112 +  void SetMsgFlags (uint16_t v);
  19.113 +  void SetMsgType (uint16_t v);
  19.114 +  void SetMsgSeq (uint32_t v);
  19.115 +  void SetMsgPid (uint32_t v);
  19.116 +  uint32_t GetMsgLen (void) const;
  19.117 +  uint16_t GetMsgFlags (void) const;
  19.118 +  uint16_t GetMsgType (void) const;
  19.119 +  uint32_t GetMsgSeq (void) const;
  19.120 +  uint32_t GetMsgPid (void) const;
  19.121 +
  19.122 +  static uint32_t GetHeaderSize ();
  19.123 +  uint32_t GetPayloadSize (void) const;
  19.124 +
  19.125 +private:
  19.126 +  static const uint32_t NETLINK_MSG_HEADER_SIZE = 16; /* size of the nlmsghdr field*/
  19.127 +  uint32_t m_nlmsgLen;	/* Length of message including header */
  19.128 +  uint16_t m_nlmsgType;	/* Message content */
  19.129 +  uint16_t m_nlmsgFlags;	/* Additional flags */
  19.130 +  uint32_t m_nlmsgSeq;	/* Sequence number */
  19.131 +  uint32_t m_nlmsgPid;	/* Sending process PID */
  19.132 +};
  19.133 +
  19.134 +/**
  19.135 +* \brief The struct nlmsgerr
  19.136 +*/
  19.137 +class NetlinkMessageError : public NetlinkPayload
  19.138 +{
  19.139 +public:
  19.140 +  NetlinkMessageError ();
  19.141 +  virtual ~NetlinkMessageError();
  19.142 +
  19.143 +  static TypeId GetTypeId (void);
  19.144 +  virtual TypeId GetInstanceTypeId (void) const;
  19.145 +  virtual void Serialize (Buffer::Iterator& start) const;
  19.146 +  virtual uint32_t Deserialize (Buffer::Iterator& start);
  19.147 +  virtual void Print (std::ostream &os) const;
  19.148 +  virtual uint32_t GetSerializedSize (void) const;
  19.149 +
  19.150 +  void SetError (int32_t v);
  19.151 +  int32_t GetError (void) const;
  19.152 +  void SetMsg(NetlinkMessageHeader v);
  19.153 +  NetlinkMessageHeader GetMsg (void) const;
  19.154 +
  19.155 +private:
  19.156 +  static const int NETLINK_MSG_ERROR_SIZE = 20; /* size of the nlmsgerror field*/
  19.157 +  int32_t m_error;
  19.158 +  NetlinkMessageHeader m_msg;        
  19.159 +};
  19.160 +
  19.161 +
  19.162 +class NetlinkMessage : public ObjectBase
  19.163 +{
  19.164 +public:
  19.165 +  NetlinkMessage ();
  19.166 +
  19.167 +  static TypeId GetTypeId (void);
  19.168 +  TypeId GetInstanceTypeId (void) const;
  19.169 +  void Print (std::ostream &os) const;
  19.170 +  uint32_t GetSerializedSize (void) const;
  19.171 +  void Serialize (Buffer::Iterator& start) const;
  19.172 +  uint32_t Deserialize (Buffer::Iterator& start);
  19.173 +
  19.174 +  operator MultipartNetlinkMessage (void) const;
  19.175 +
  19.176 +  uint32_t GetTotalSize (void) const;  //length of netlink message including padding
  19.177 +  uint32_t GetMsgSize (void) const;    //length of netlink message not including padding
  19.178 +  uint32_t GetPayloadSize (void) const; //length of message payload
  19.179 +  uint16_t GetMsgType (void) const;
  19.180 +  uint8_t GetFamily(void) const;
  19.181 +
  19.182 +  void SetHeader (NetlinkMessageHeader hdr);
  19.183 +  NetlinkMessageHeader GetHeader (void) const;
  19.184 +
  19.185 +  //before set message body, should set header first
  19.186 +  void SetErrorMessage (NetlinkMessageError errmsg);
  19.187 +  void SetGeneralMessage (GeneralMessage genmsg);
  19.188 +  void SetInterfaceInfoMessage (InterfaceInfoMessage v);
  19.189 +  void SetInterfaceAddressMessage (InterfaceAddressMessage v);
  19.190 +  void SetRouteMessage (RouteMessage v);
  19.191 +  NetlinkMessageError GetErrorMessage (void) const;
  19.192 +  GeneralMessage GetGeneralMessage (void) const;
  19.193 +  InterfaceInfoMessage GetInterfaceInfoMessage (void) const;
  19.194 +  InterfaceAddressMessage GetInterfaceAddressMessage (void) const;
  19.195 +  RouteMessage GetRouteMessage (void) const;
  19.196 +
  19.197 +  /**
  19.198 +  * \returns true if type was control type, false otherwise.
  19.199 +  */
  19.200 +  static bool IsMessageNetlinkControl (uint16_t type);
  19.201 +  /**
  19.202 +  * \returns true if type was netlink route, false otherwise.
  19.203 +  */
  19.204 +  static bool IsMessageNetlinkRoute (uint16_t type);
  19.205 +  static bool IsMessageAddress (uint16_t type);
  19.206 +  static bool IsMessageInterface (uint16_t type);
  19.207 +  static bool IsMessageRoute (uint16_t type);
  19.208 +  /**
  19.209 +  * \returns true if type was GETxxx , false otherwise.
  19.210 +  */
  19.211 +  static bool IsMessageTypeGet (uint16_t type);
  19.212 +  /**
  19.213 +  * \returns true if flag has ack , false otherwise.
  19.214 +  */
  19.215 +  static bool IsMessageFlagsAck (uint16_t flags);
  19.216 +  /**
  19.217 +  * \returns true if flag has request , false otherwise.
  19.218 +  */
  19.219 +  static bool IsMessageFlagsRequest (uint16_t flags);
  19.220 +  /**
  19.221 +  * \returns true if flag has dump , false otherwise.
  19.222 +  */
  19.223 +  static bool IsMessageFlagsDump (uint16_t flags);
  19.224 +
  19.225 +private:
  19.226 +  NetlinkMessageHeader m_hdr;
  19.227 +
  19.228 +  //only one type of messages below exists in real world application
  19.229 +  NetlinkMessageError m_errorMessage;  
  19.230 +  GeneralMessage m_genmsg;
  19.231 +  InterfaceInfoMessage m_interfaceTemplate;
  19.232 +  InterfaceAddressMessage m_addressTemplate;
  19.233 +  RouteMessage m_routeTemplate;
  19.234 +};
  19.235 +
  19.236 +class MultipartNetlinkMessage : public Header
  19.237 +{
  19.238 +public:
  19.239 +  MultipartNetlinkMessage ();
  19.240 +
  19.241 +  static TypeId GetTypeId (void);
  19.242 +  virtual TypeId GetInstanceTypeId (void) const;
  19.243 +  virtual void Print (std::ostream &os) const;
  19.244 +  virtual uint32_t GetSerializedSize (void) const;
  19.245 +  virtual void Serialize (Buffer::Iterator start) const;
  19.246 +  virtual uint32_t Deserialize (Buffer::Iterator start);
  19.247 +
  19.248 +  void AppendMessage (NetlinkMessage nlmsg);
  19.249 +  void Clear();
  19.250 +  uint32_t GetNMessages (void) const;
  19.251 +  NetlinkMessage GetMessage (uint32_t index) const;
  19.252 +
  19.253 +private:
  19.254 +  std::vector<NetlinkMessage> m_netlinkMessages;
  19.255 +};
  19.256 +
  19.257 +}; // namespace ns3
  19.258 +
  19.259 +#endif /* NETLINK_MESSAGE_H */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/model/netlink-socket-address.cc	Mon Apr 18 12:13:02 2011 +0200
    20.3 @@ -0,0 +1,121 @@
    20.4 +/* -*-	Mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    20.5 +/*
    20.6 + * Copyright (c) 2008 Liu Jian
    20.7 + *
    20.8 + * This program is free software; you can redistribute it and/or modify
    20.9 + * it under the terms of the GNU General Public License version 2 as
   20.10 + * published by the Free Software Foundation;
   20.11 + *
   20.12 + * This program is distributed in the hope that it will be useful,
   20.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20.15 + * GNU General Public License for more details.
   20.16 + *
   20.17 + * You should have received a copy of the GNU General Public License
   20.18 + * along with this program; if not, write to the Free Software
   20.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   20.20 + *
   20.21 + * Author: Liu Jian <liujatp@gmail.com>
   20.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   20.23 + */
   20.24 +
   20.25 +#include "netlink-socket-address.h"
   20.26 +
   20.27 +namespace ns3 {
   20.28 +
   20.29 +NetlinkSocketAddress::NetlinkSocketAddress (uint32_t pid, uint32_t groups)
   20.30 +  : m_pid(pid),
   20.31 +    m_groups(groups)
   20.32 +{}
   20.33 +
   20.34 +NetlinkSocketAddress::NetlinkSocketAddress ()
   20.35 +  : m_pid (0),
   20.36 +    m_groups (0)
   20.37 +{}
   20.38 +
   20.39 +NetlinkSocketAddress::~NetlinkSocketAddress ()
   20.40 +{}
   20.41 +
   20.42 +void NetlinkSocketAddress::SetProcessID (uint32_t pid)
   20.43 +{
   20.44 +  m_pid = pid;
   20.45 +}
   20.46 +
   20.47 +void NetlinkSocketAddress::SetGroupsMask (uint32_t mask)
   20.48 +{
   20.49 +  m_groups = mask;
   20.50 +}
   20.51 +
   20.52 +uint32_t NetlinkSocketAddress::GetProcessID (void) const
   20.53 +{
   20.54 +  return m_pid;
   20.55 +}
   20.56 +
   20.57 +uint32_t NetlinkSocketAddress::GetGroupsMask (void) const
   20.58 +{
   20.59 +  return m_groups;
   20.60 +}
   20.61 +
   20.62 +NetlinkSocketAddress::operator Address (void) const
   20.63 +{
   20.64 +  return ConvertTo ();
   20.65 +}
   20.66 +
   20.67 +Address NetlinkSocketAddress::ConvertTo (void) const
   20.68 +{
   20.69 +  uint8_t buffer[8];
   20.70 +
   20.71 +  buffer[0] = (m_pid >> 24) & 0xff;
   20.72 +  buffer[1] = (m_pid >> 16) & 0xff;
   20.73 +  buffer[2] = (m_pid >> 8) & 0xff;
   20.74 +  buffer[3] = (m_pid >> 0) & 0xff;
   20.75 +  buffer[4] = (m_groups >> 24) & 0xff;
   20.76 +  buffer[5] = (m_groups >> 16) & 0xff;
   20.77 +  buffer[6] = (m_groups >> 8) & 0xff;
   20.78 +  buffer[7] = (m_groups >> 0) & 0xff;
   20.79 +
   20.80 +  return Address (GetType (), buffer, 8);
   20.81 +}
   20.82 +
   20.83 +NetlinkSocketAddress NetlinkSocketAddress::ConvertFrom (const Address &address)
   20.84 +{
   20.85 +  NS_ASSERT (IsMatchingType (address));
   20.86 +
   20.87 +  NetlinkSocketAddress nl;
   20.88 +  uint8_t buf[8];
   20.89 +
   20.90 +  address.CopyTo (buf);
   20.91 +
   20.92 +  nl.m_pid = 0;
   20.93 +  nl.m_pid |= buf[0];
   20.94 +  nl.m_pid <<= 8;
   20.95 +  nl.m_pid |= buf[1];
   20.96 +  nl.m_pid <<= 8;
   20.97 +  nl.m_pid |= buf[2];
   20.98 +  nl.m_pid <<= 8;
   20.99 +  nl.m_pid |= buf[3];
  20.100 +
  20.101 +  nl.m_groups = 0;
  20.102 +  nl.m_groups |= buf[4];
  20.103 +  nl.m_groups <<= 8;
  20.104 +  nl.m_groups |= buf[5];
  20.105 +  nl.m_groups <<= 8;
  20.106 +  nl.m_groups |= buf[6];
  20.107 +  nl.m_groups <<= 8;
  20.108 +  nl.m_groups |= buf[7];
  20.109 +
  20.110 +  return nl;
  20.111 +}
  20.112 +
  20.113 +bool NetlinkSocketAddress::IsMatchingType (const Address &address)
  20.114 +{
  20.115 +  return address.IsMatchingType (GetType ());
  20.116 +}
  20.117 +
  20.118 +uint8_t NetlinkSocketAddress::GetType (void)
  20.119 +{
  20.120 +  static uint8_t type = Address::Register ();
  20.121 +  return type;
  20.122 +}
  20.123 +
  20.124 +} // namespace ns3
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/model/netlink-socket-address.h	Mon Apr 18 12:13:02 2011 +0200
    21.3 @@ -0,0 +1,71 @@
    21.4 +/* -*-	Mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    21.5 +/*
    21.6 + * Copyright (c) 2008 Liu Jian
    21.7 + *
    21.8 + * This program is free software; you can redistribute it and/or modify
    21.9 + * it under the terms of the GNU General Public License version 2 as
   21.10 + * published by the Free Software Foundation;
   21.11 + *
   21.12 + * This program is distributed in the hope that it will be useful,
   21.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21.15 + * GNU General Public License for more details.
   21.16 + *
   21.17 + * You should have received a copy of the GNU General Public License
   21.18 + * along with this program; if not, write to the Free Software
   21.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21.20 + *
   21.21 + * Author: Liu Jian <liujatp@gmail.com>
   21.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   21.23 + */
   21.24 +
   21.25 +#ifndef NETLINK_SOCKET_ADDRESS_H
   21.26 +#define NETLINK_SOCKET_ADDRESS_H
   21.27 +
   21.28 +#include "ns3/ptr.h"
   21.29 +#include "ns3/address.h"
   21.30 +
   21.31 +namespace ns3 {
   21.32 +
   21.33 +class NetlinkSocketAddress
   21.34 +{
   21.35 +public:
   21.36 +  NetlinkSocketAddress (uint32_t pid, uint32_t groups);
   21.37 +  NetlinkSocketAddress ();
   21.38 +  ~NetlinkSocketAddress ();
   21.39 +
   21.40 +  void SetProcessID (uint32_t pid);
   21.41 +  void SetGroupsMask (uint32_t mask);
   21.42 +
   21.43 +  uint32_t GetProcessID (void) const;
   21.44 +  uint32_t GetGroupsMask (void) const;
   21.45 +
   21.46 +  /**
   21.47 +  * \returns an Address instance which represents this
   21.48 +  * NetlinkSocketAddress instance.
   21.49 +  */
   21.50 +  operator Address (void) const;
   21.51 +  /**
   21.52 +  * \param address the Address instance to convert from.
   21.53 +  *
   21.54 +  * Returns an NetlinkSocketAddress which corresponds to the input
   21.55 +  * Address
   21.56 +  */
   21.57 +  static NetlinkSocketAddress ConvertFrom (const Address &address);
   21.58 +  /**
   21.59 +  * \returns true if the address matches, false otherwise.
   21.60 +  */
   21.61 +  static bool IsMatchingType (const Address &address);
   21.62 +private:
   21.63 +  static uint8_t GetType (void);
   21.64 +  Address ConvertTo (void) const;
   21.65 +
   21.66 +  uint32_t m_pid;
   21.67 +  uint32_t m_groups;
   21.68 +
   21.69 +};
   21.70 +
   21.71 +
   21.72 +} // namespace ns3
   21.73 +
   21.74 +#endif /* NETLINK_SOCKET_ADDRESS_H */
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/model/netlink-socket-factory.cc	Mon Apr 18 12:13:02 2011 +0200
    22.3 @@ -0,0 +1,48 @@
    22.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    22.5 +/*
    22.6 + * Copyright (c) 2008 Liu Jian
    22.7 + *
    22.8 + * This program is free software; you can redistribute it and/or modify
    22.9 + * it under the terms of the GNU General Public License version 2 as
   22.10 + * published by the Free Software Foundation;
   22.11 + *
   22.12 + * This program is distributed in the hope that it will be useful,
   22.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22.15 + * GNU General Public License for more details.
   22.16 + *
   22.17 + * You should have received a copy of the GNU General Public License
   22.18 + * along with this program; if not, write to the Free Software
   22.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22.20 + *
   22.21 + * Author: Liu Jian <liujatp@gmail.com>
   22.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   22.23 + */
   22.24 +
   22.25 +#include "netlink-socket-factory.h"
   22.26 +#include "netlink-socket.h"
   22.27 +#include "ns3/node.h"
   22.28 +
   22.29 +namespace ns3 {
   22.30 +
   22.31 +NS_OBJECT_ENSURE_REGISTERED (NetlinkSocketFactory);
   22.32 +
   22.33 +TypeId 
   22.34 +NetlinkSocketFactory::GetTypeId (void)
   22.35 +{
   22.36 +  static TypeId tid = TypeId ("ns3::NetlinkSocketFactory")
   22.37 +    .SetParent<SocketFactory> ();
   22.38 +  return tid;
   22.39 +}
   22.40 +
   22.41 +NetlinkSocketFactory::NetlinkSocketFactory ()
   22.42 +{}
   22.43 +
   22.44 +Ptr<Socket> NetlinkSocketFactory::CreateSocket (void)
   22.45 +{
   22.46 +  Ptr<Node> node = GetObject<Node> ();
   22.47 +  Ptr<NetlinkSocket> socket = CreateObject<NetlinkSocket> ();
   22.48 +  socket->SetNode (node);
   22.49 +  return socket;
   22.50 +} 
   22.51 +} // namespace ns3
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/model/netlink-socket-factory.h	Mon Apr 18 12:13:02 2011 +0200
    23.3 @@ -0,0 +1,52 @@
    23.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    23.5 +/*
    23.6 + * Copyright (c) 2008 Liu Jian
    23.7 + *
    23.8 + * This program is free software; you can redistribute it and/or modify
    23.9 + * it under the terms of the GNU General Public License version 2 as
   23.10 + * published by the Free Software Foundation;
   23.11 + *
   23.12 + * This program is distributed in the hope that it will be useful,
   23.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23.15 + * GNU General Public License for more details.
   23.16 + *
   23.17 + * You should have received a copy of the GNU General Public License
   23.18 + * along with this program; if not, write to the Free Software
   23.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23.20 + *
   23.21 + * Author: Liu Jian <liujatp@gmail.com>
   23.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   23.23 + */
   23.24 +
   23.25 +#ifndef NETLINK_SOCKET_FACTORY_H
   23.26 +#define NETLINK_SOCKET_FACTORY_H
   23.27 +
   23.28 +#include "ns3/socket-factory.h"
   23.29 +
   23.30 +namespace ns3 {
   23.31 +
   23.32 +class Socket;
   23.33 +
   23.34 +/**
   23.35 + * This can be used as an interface in a node in order for the node to
   23.36 + * generate NetlinkSockets.
   23.37 + */
   23.38 +class NetlinkSocketFactory : public SocketFactory
   23.39 +{
   23.40 +public:
   23.41 +  static TypeId GetTypeId (void);
   23.42 +
   23.43 +  NetlinkSocketFactory ();
   23.44 +
   23.45 +  /**
   23.46 +   * Creates a NetlinkSocket and returns a pointer to it.
   23.47 +   *
   23.48 +   * \return a pointer to the created socket
   23.49 +   */
   23.50 +  virtual Ptr<Socket> CreateSocket (void);
   23.51 +};
   23.52 +
   23.53 +} // namespace ns3
   23.54 +
   23.55 +#endif /* NETLINK_SOCKET_FACTORY_H */
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/model/netlink-socket.cc	Mon Apr 18 12:13:02 2011 +0200
    24.3 @@ -0,0 +1,1571 @@
    24.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    24.5 +/*
    24.6 + * Copyright (c) 2008 Liu Jian
    24.7 + *
    24.8 + * This program is free software; you can redistribute it and/or modify
    24.9 + * it under the terms of the GNU General Public License version 2 as
   24.10 + * published by the Free Software Foundation;
   24.11 + *
   24.12 + * This program is distributed in the hope that it will be useful,
   24.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   24.15 + * GNU General Public License for more details.
   24.16 + *
   24.17 + * You should have received a copy of the GNU General Public License
   24.18 + * along with this program; if not, write to the Free Software
   24.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24.20 + *
   24.21 + * Author: Liu Jian <liujatp@gmail.com>
   24.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   24.23 + */
   24.24 +
   24.25 +#include "netlink-socket.h"
   24.26 +#include "netlink-socket-address.h"
   24.27 +#include "netlink-message.h"
   24.28 +#include "netlink-message-route.h"
   24.29 +#include "ns3/log.h"
   24.30 +#include "ns3/node.h"
   24.31 +#include "ns3/packet.h"
   24.32 +#include "ns3/ipv4-address.h"
   24.33 +#include "ns3/ipv4.h"
   24.34 +#include "ns3/simple-net-device.h"
   24.35 +#include "ns3/uinteger.h"
   24.36 +#include "ns3/trace-source-accessor.h"
   24.37 +#include <iostream>
   24.38 +#include <sstream>
   24.39 +#include "ns3/ipv6-address.h"
   24.40 +#include "ns3/ipv6.h"
   24.41 +#include "ns3/ipv4-l3-protocol.h"
   24.42 +#include "ns3/ipv4-static-routing-helper.h"
   24.43 +#include "ns3/ipv4-routing-table-entry.h"
   24.44 +#include "ns3/ipv6-l3-protocol.h"
   24.45 +#include "ns3/ipv6-interface.h"
   24.46 +#include "ns3/ipv6-static-routing-helper.h"
   24.47 +#include "ns3/ipv6-routing-table-entry.h"
   24.48 +#include "ns3/socket.h"
   24.49 +#include "ns3/mac48-address.h"
   24.50 +#include <sys/socket.h>
   24.51 +#include <linux/if.h>
   24.52 +#include <errno.h>
   24.53 +
   24.54 +NS_LOG_COMPONENT_DEFINE ("NetlinkSocket");
   24.55 +
   24.56 +namespace ns3 {
   24.57 +
   24.58 +// GroupSockets store the netlinksocket with noero group value
   24.59 +// it was due to the mulitcast netlink messages.
   24.60 +class GroupSockets
   24.61 +{
   24.62 +public:
   24.63 +  static uint32_t GetNSockets(void)
   24.64 +  { 
   24.65 +    return m_Sockets.size();
   24.66 +  }
   24.67 +  static Ptr<NetlinkSocket> GetSocket(uint32_t index)
   24.68 +  {
   24.69 +    NS_ASSERT(index < m_Sockets.size());
   24.70 +    return m_Sockets[index];
   24.71 +  }
   24.72 +  static void AddSocket(Ptr<NetlinkSocket>sock)
   24.73 +  {
   24.74 +    m_Sockets.push_back(sock);
   24.75 +  }
   24.76 +private:
   24.77 +   /*use a std::vector to store the sockets with nozero group value*/
   24.78 +  static std::vector<Ptr<NetlinkSocket> >m_Sockets;
   24.79 +};
   24.80 +std::vector<Ptr<NetlinkSocket> >GroupSockets::m_Sockets;
   24.81 +
   24.82 +NS_OBJECT_ENSURE_REGISTERED (NetlinkSocket);
   24.83 +
   24.84 +/*
   24.85 +Netlink Socket
   24.86 +*/
   24.87 +TypeId
   24.88 +NetlinkSocket::GetTypeId (void)
   24.89 +{
   24.90 +  static TypeId tid = TypeId ("ns3::NetlinkSocket")
   24.91 +    .SetParent<Socket> ()
   24.92 +    .AddConstructor<NetlinkSocket> ()
   24.93 +    .AddTraceSource ("Drop", "Drop packet due to receive buffer overflow",
   24.94 +                     MakeTraceSourceAccessor (&NetlinkSocket::m_dropTrace))
   24.95 +    .AddAttribute ("RcvBufSize",
   24.96 +                   "NetlinkSocket maximum receive buffer size (bytes)",
   24.97 +                   UintegerValue (0xffffffffl),
   24.98 +                   MakeUintegerAccessor (&NetlinkSocket::m_rcvBufSize),
   24.99 +                   MakeUintegerChecker<uint32_t> ())
  24.100 +    .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is received on this socket.",
  24.101 +                   CallbackValue (),
  24.102 +                   MakeCallbackAccessor (&NetlinkSocket::m_icmpCallback),
  24.103 +                   MakeCallbackChecker ())
  24.104 +    ;
  24.105 +  return tid;
  24.106 +}
  24.107 +
  24.108 +NetlinkSocket::NetlinkSocket ()
  24.109 +  : m_shutdownSend (false),
  24.110 +    m_shutdownRecv (false),
  24.111 +    m_rxAvailable (0),
  24.112 +    m_srcPid (0),
  24.113 +    m_srcGroups (0),
  24.114 +    m_dstPid (0),
  24.115 +    m_dstGroups (0)
  24.116 +{
  24.117 +  NS_LOG_FUNCTION_NOARGS ();
  24.118 +  m_errno = ERROR_NOTERROR;
  24.119 +}
  24.120 +NetlinkSocket::~NetlinkSocket ()
  24.121 +{
  24.122 +  NS_LOG_FUNCTION (this);
  24.123 +}
  24.124 +void 
  24.125 +NetlinkSocket::DoDispose (void)
  24.126 +{
  24.127 +  NS_LOG_FUNCTION_NOARGS ();
  24.128 +}
  24.129 +
  24.130 +int
  24.131 +NetlinkSocket::ErrnoToSimuErrno (void)
  24.132 +{
  24.133 +  switch (m_errno)
  24.134 +    {
  24.135 +    case Socket::ERROR_ISCONN:
  24.136 +      return EISCONN;
  24.137 +    case Socket::ERROR_NOTCONN:
  24.138 +      return ENOTCONN;
  24.139 +    case Socket::ERROR_MSGSIZE:
  24.140 +      return EMSGSIZE;
  24.141 +    case Socket::ERROR_AGAIN:
  24.142 +      return EAGAIN;
  24.143 +    case Socket::ERROR_SHUTDOWN:
  24.144 +      return ESHUTDOWN;
  24.145 +    case Socket::ERROR_OPNOTSUPP:
  24.146 +      return EOPNOTSUPP;
  24.147 +    case Socket::ERROR_AFNOSUPPORT:
  24.148 +      return EAFNOSUPPORT;
  24.149 +    case Socket::ERROR_INVAL:
  24.150 +      return EINVAL;
  24.151 +    case Socket::ERROR_BADF:
  24.152 +      return EBADF;
  24.153 +    case Socket::ERROR_NOROUTETOHOST:
  24.154 +      return EHOSTUNREACH;
  24.155 +    case Socket::ERROR_NODEV:
  24.156 +      return ENODEV;
  24.157 +    case Socket::ERROR_ADDRNOTAVAIL:
  24.158 +      return EADDRNOTAVAIL;
  24.159 +    case Socket::SOCKET_ERRNO_LAST:
  24.160 +    case Socket::ERROR_NOTERROR:
  24.161 +    default:
  24.162 +      NS_ASSERT (false);
  24.163 +      return 0; // quiet compiler
  24.164 +      break;
  24.165 +    }
  24.166 +}
  24.167 +
  24.168 +void 
  24.169 +NetlinkSocket::SetNode (Ptr<Node> node)
  24.170 +{
  24.171 +  NS_LOG_FUNCTION_NOARGS ();
  24.172 +  m_node = node;
  24.173 +}
  24.174 +
  24.175 +
  24.176 +enum Socket::SocketErrno
  24.177 +NetlinkSocket::GetErrno (void) const
  24.178 +{
  24.179 +  NS_LOG_FUNCTION_NOARGS ();
  24.180 +  return m_errno;
  24.181 +}
  24.182 +enum Socket::SocketType 
  24.183 +NetlinkSocket::GetSocketType (void) const
  24.184 +{
  24.185 +  return Socket::NS3_SOCK_DGRAM;
  24.186 +}
  24.187 +
  24.188 +Ptr<Node>
  24.189 +NetlinkSocket::GetNode (void) const
  24.190 +{
  24.191 +  NS_LOG_FUNCTION_NOARGS ();
  24.192 +  return m_node;
  24.193 +}
  24.194 +
  24.195 +uint32_t
  24.196 +NetlinkSocket::GetSrcPid (void) const
  24.197 +{
  24.198 +  NS_LOG_FUNCTION_NOARGS ();
  24.199 +  return m_srcPid;
  24.200 +}
  24.201 +uint32_t
  24.202 +NetlinkSocket::GetSrcGroups (void)const
  24.203 +{
  24.204 +  NS_LOG_FUNCTION_NOARGS ();
  24.205 +  return m_srcGroups;
  24.206 +}
  24.207 +uint32_t
  24.208 +NetlinkSocket::GetDstPid (void) const
  24.209 +{
  24.210 +  NS_LOG_FUNCTION_NOARGS ();
  24.211 +  return m_dstPid;
  24.212 +}
  24.213 +uint32_t
  24.214 +NetlinkSocket::GetDstGroups (void)const
  24.215 +{
  24.216 +  NS_LOG_FUNCTION_NOARGS ();
  24.217 +  return m_dstGroups;
  24.218 +}
  24.219 +
  24.220 +int
  24.221 +NetlinkSocket::Bind (void)
  24.222 +{
  24.223 +  NS_LOG_FUNCTION_NOARGS ();
  24.224 +  NetlinkSocketAddress address;
  24.225 +  return DoBind (address);
  24.226 +}
  24.227 +int
  24.228 +NetlinkSocket::Bind (const Address &address)
  24.229 +{ 
  24.230 +  NS_LOG_FUNCTION (this << address);
  24.231 +
  24.232 +  if (!NetlinkSocketAddress::IsMatchingType (address))
  24.233 +    {
  24.234 +      m_errno = ERROR_INVAL;
  24.235 +      return -1;
  24.236 +    }
  24.237 +  NetlinkSocketAddress ad = NetlinkSocketAddress::ConvertFrom (address);
  24.238 +  return DoBind (ad);
  24.239 +}
  24.240 +int
  24.241 +NetlinkSocket::DoBind (const NetlinkSocketAddress &address)
  24.242 +{
  24.243 +  NS_LOG_FUNCTION (this << address);
  24.244 +
  24.245 +  m_srcPid = address.GetProcessID ();
  24.246 +  m_srcGroups = address.GetGroupsMask ();
  24.247 +
  24.248 +  if (m_srcGroups)
  24.249 +    {
  24.250 +      GroupSockets::AddSocket(this);
  24.251 +    } 
  24.252 +  return 0;
  24.253 +}
  24.254 +
  24.255 +int 
  24.256 +NetlinkSocket::Listen (void)
  24.257 +{
  24.258 +  NS_LOG_FUNCTION_NOARGS ();
  24.259 +  m_errno = Socket::ERROR_OPNOTSUPP;
  24.260 +  return -1;
  24.261 +}
  24.262 +
  24.263 +uint32_t
  24.264 +NetlinkSocket::GetTxAvailable (void) const
  24.265 +{
  24.266 +  NS_LOG_FUNCTION_NOARGS ();
  24.267 +  return 0;
  24.268 +}
  24.269 +uint32_t
  24.270 +NetlinkSocket::GetRxAvailable (void) const
  24.271 +{
  24.272 +  NS_LOG_FUNCTION_NOARGS ();
  24.273 +  // We separately maintain this state to avoid walking the queue 
  24.274 +  // every time this might be called
  24.275 +  return m_rxAvailable;
  24.276 +}
  24.277 +
  24.278 +int
  24.279 +NetlinkSocket::ShutdownSend (void)
  24.280 +{
  24.281 +  NS_LOG_FUNCTION_NOARGS ();
  24.282 +  m_shutdownSend = true;
  24.283 +  return 0;
  24.284 +}
  24.285 +int
  24.286 +NetlinkSocket::ShutdownRecv (void)
  24.287 +{
  24.288 +  NS_LOG_FUNCTION_NOARGS ();
  24.289 +  m_shutdownRecv = true;
  24.290 +  return 0;
  24.291 +}
  24.292 +
  24.293 +int
  24.294 +NetlinkSocket::Close (void)
  24.295 +{
  24.296 +  NS_LOG_FUNCTION_NOARGS ();
  24.297 +  ShutdownSend();
  24.298 +  ShutdownRecv();
  24.299 +  return 0;
  24.300 +}
  24.301 +
  24.302 +int
  24.303 +NetlinkSocket::Connect (const Address &address)
  24.304 +{
  24.305 +  NS_LOG_FUNCTION (this << address);
  24.306 +  m_errno = Socket::ERROR_OPNOTSUPP;
  24.307 +  return 0;
  24.308 +}
  24.309 +
  24.310 +Ptr<Packet>
  24.311 +NetlinkSocket::Recv (uint32_t maxSize, uint32_t flags)
  24.312 +{
  24.313 +  NS_LOG_FUNCTION (this << maxSize<< flags);
  24.314 +  if (m_dataReceiveQueue.empty())
  24.315 +    {
  24.316 +      return 0;
  24.317 +    }
  24.318 +
  24.319 +  Ptr<Packet> p = m_dataReceiveQueue.front ();
  24.320 +  if (p->GetSize () <= maxSize) 
  24.321 +    {
  24.322 +      m_dataReceiveQueue.pop ();
  24.323 +      m_rxAvailable -= p->GetSize ();
  24.324 +    }
  24.325 +  else
  24.326 +    {
  24.327 +      p = 0; 
  24.328 +    }
  24.329 +  return p;
  24.330 +}
  24.331 +
  24.332 +Ptr<Packet>
  24.333 +NetlinkSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
  24.334 +{
  24.335 +  NS_LOG_FUNCTION (this << maxSize << flags << fromAddress);
  24.336 +  Ptr<Packet> packet = Recv (maxSize, flags);
  24.337 +  if (packet != 0)
  24.338 +    {
  24.339 +      SocketAddressTag tag;
  24.340 +      bool found;
  24.341 +      found = packet->FindFirstMatchingByteTag (tag);
  24.342 +      NS_ASSERT (found);
  24.343 +      fromAddress = tag.GetAddress ();
  24.344 +    }
  24.345 +  return packet;
  24.346 +}
  24.347 +
  24.348 +int
  24.349 +NetlinkSocket::Send (Ptr<Packet> p,uint32_t flags)
  24.350 +{
  24.351 +  NS_LOG_FUNCTION (this << p << flags);
  24.352 +  NetlinkSocketAddress address = NetlinkSocketAddress(m_dstPid, m_dstGroups);
  24.353 +  return SendTo(p, flags, address);
  24.354 +}
  24.355 +
  24.356 +int
  24.357 +NetlinkSocket::SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress)
  24.358 +{
  24.359 +  NS_LOG_FUNCTION (this << p << flags << toAddress);
  24.360 +  NetlinkSocketAddress ad;
  24.361 +
  24.362 +  if (!NetlinkSocketAddress::IsMatchingType (toAddress))
  24.363 +    {
  24.364 +      NS_LOG_LOGIC ("ERROR_AFNOSUPPORT");
  24.365 +      m_errno = ERROR_AFNOSUPPORT;
  24.366 +      return -1;
  24.367 +    }
  24.368 +  ad = NetlinkSocketAddress::ConvertFrom (toAddress);
  24.369 +  m_dstPid = ad.GetProcessID();
  24.370 +  m_dstGroups = ad.GetGroupsMask();
  24.371 +  NS_LOG_INFO ("send netlink message to pid = " << m_dstPid << ", groups = " << m_dstGroups);
  24.372 +  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending netlink message from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ());
  24.373 +
  24.374 +  //Ptr<NetlinkSocket>kernel_socket = GetNetlinkSocketByAddress(ad);
  24.375 +  //kernel_socket->m_receivedData.push_back(p);
  24.376 +  //kernel_socket->NotifyDataReceived(p);
  24.377 +
  24.378 +  //when netlink socket send packet, the first step is to find the dest netlink socket through address
  24.379 +  //then send the packet to it. For we partly implement the netlink-family, the dest address
  24.380 +  //is always the kernel(pid = 0), (Actually, there must be one static kernel netlink socket to
  24.381 +  //receive/handle messages), we do not setup a kernel socket to receive packet.
  24.382 +  //
  24.383 +  
  24.384 +  MultipartNetlinkMessage multipartnlmsg;
  24.385 +  uint32_t packet_len, remain_len;
  24.386 +
  24.387 +  packet_len = p->GetSize ();
  24.388 +  remain_len = packet_len;
  24.389 +
  24.390 +  while (remain_len > NetlinkMessageHeader::GetHeaderSize ())
  24.391 +    {
  24.392 +      remain_len -= p->RemoveHeader (multipartnlmsg);
  24.393 +      NS_ASSERT (remain_len == p->GetSize ());
  24.394 +
  24.395 +      //actually, message to kernel contains single one netlink message
  24.396 +      for (uint32_t i = 0; i < multipartnlmsg.GetNMessages(); i ++)
  24.397 +        {
  24.398 +          NetlinkMessage nlmsg = multipartnlmsg.GetMessage (i);
  24.399 +          if (HandleMessage (nlmsg) < 0)
  24.400 +            {
  24.401 +              if (m_errno)
  24.402 +                {
  24.403 +                  SendAckMessage (nlmsg, -ErrnoToSimuErrno ());
  24.404 +                }
  24.405 +            }
  24.406 +          else if (NetlinkMessage::IsMessageFlagsAck (nlmsg.GetHeader ().GetMsgFlags ()))
  24.407 +            {
  24.408 +              SendAckMessage (nlmsg, 0);
  24.409 +            }
  24.410 +        }
  24.411 +    }
  24.412 +
  24.413 +  NotifyDataSent (packet_len);
  24.414 +  NS_LOG_INFO ("netlink socket kernel error " << -m_errno);
  24.415 +  return packet_len;
  24.416 +}
  24.417 +
  24.418 +int
  24.419 +NetlinkSocket::GetSockName (Address &address) const
  24.420 +{
  24.421 +  NS_LOG_FUNCTION_NOARGS ();
  24.422 +  NetlinkSocketAddress ad;
  24.423 +
  24.424 +  ad.SetProcessID (GetSrcPid ());
  24.425 +  ad.SetGroupsMask (GetSrcGroups ());
  24.426 +  address = ad;
  24.427 +  return 0;
  24.428 +}
  24.429 +int
  24.430 +NetlinkSocket::GetPeerName (Address &address) const
  24.431 +{
  24.432 +  NS_LOG_FUNCTION_NOARGS ();
  24.433 +  // XXX
  24.434 +  NS_ASSERT (false);
  24.435 +  return -1;
  24.436 +}
  24.437 +bool 
  24.438 +NetlinkSocket::SetAllowBroadcast (bool allowBroadcast)
  24.439 +{
  24.440 +  NS_ASSERT (false);
  24.441 +  return false;
  24.442 +}
  24.443 +bool 
  24.444 +NetlinkSocket::GetAllowBroadcast () const
  24.445 +{
  24.446 +  NS_ASSERT (false);
  24.447 +  return false;
  24.448 +}
  24.449 +
  24.450 +
  24.451 +void
  24.452 +NetlinkSocket::ForwardUp (Ptr<Packet> packet, NetlinkSocketAddress &address)
  24.453 +{
  24.454 +  NS_LOG_FUNCTION (this << packet << address);
  24.455 +
  24.456 +  if (m_shutdownRecv)
  24.457 +    {
  24.458 +      return;
  24.459 +    }
  24.460 +  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
  24.461 +    {
  24.462 +      SocketAddressTag tag;
  24.463 +      tag.SetAddress (address);
  24.464 +      packet->AddByteTag (tag);
  24.465 +      m_dataReceiveQueue.push (packet);
  24.466 +      m_rxAvailable += packet->GetSize ();
  24.467 +      NotifyDataRecv ();
  24.468 +    }
  24.469 +  else
  24.470 +    {
  24.471 +      NS_LOG_WARN ("No receive buffer space available.  Drop.");
  24.472 +      m_dropTrace (packet);
  24.473 +    }
  24.474 +}
  24.475 +
  24.476 +int32_t
  24.477 +NetlinkSocket::SendMessageUnicast (const MultipartNetlinkMessage &nlmsg, uint32_t pid, int32_t nonblock)
  24.478 +{
  24.479 +  NS_LOG_FUNCTION (this << pid << nonblock);
  24.480 +  //here we send message instantly
  24.481 +  Ptr<Packet> p = Create<Packet> ();
  24.482 +  p->AddHeader (nlmsg);
  24.483 +
  24.484 +  NetlinkSocketAddress address;
  24.485 +  address.SetProcessID (pid);
  24.486 +
  24.487 +  //send packet to user space
  24.488 +  ForwardUp (p, address);
  24.489 +  return 0;
  24.490 +}
  24.491 +int32_t
  24.492 +NetlinkSocket::SendMessageBroadcast (const MultipartNetlinkMessage &nlmsg, 
  24.493 +                                     uint32_t pid, 
  24.494 +                                     uint32_t group,
  24.495 +                                     Ptr<Node> node)
  24.496 +{
  24.497 +  NS_LOG_FUNCTION ("SendMessageBroadcast" << pid << group);
  24.498 +  //fisrt find the dest netlink socket through group value, then attach this nlmsg to its recv-queue
  24.499 +  for (uint32_t i = 0; i < GroupSockets::GetNSockets (); i ++)
  24.500 +    {
  24.501 +      Ptr<NetlinkSocket> nlsock = GroupSockets::GetSocket (i);
  24.502 +
  24.503 +      if ((nlsock->GetSrcGroups () & group) &&
  24.504 +          (nlsock->GetSrcPid () != pid) &&
  24.505 +          node == nlsock->GetNode ())
  24.506 +        {
  24.507 +          //here we send message instantly
  24.508 +          Ptr<Packet> p = Create<Packet> ();
  24.509 +          p->AddHeader (nlmsg);
  24.510 +
  24.511 +          NetlinkSocketAddress address;
  24.512 +          address.SetProcessID (nlsock->GetSrcPid());
  24.513 +          address.SetGroupsMask (group);
  24.514 +
  24.515 +          //send packet to user space
  24.516 +          nlsock->ForwardUp (p, address);
  24.517 +        }
  24.518 +    }
  24.519 +  return 0;
  24.520 +}
  24.521 +void
  24.522 +NetlinkSocket::SendAckMessage (const NetlinkMessage&nlmsg, int32_t err)
  24.523 +{
  24.524 +  NS_LOG_FUNCTION (this << err);
  24.525 +  NetlinkMessageHeader rep;
  24.526 +  NetlinkMessage ackmsg;
  24.527 +  NetlinkMessageError errmsg;
  24.528 +
  24.529 +  rep.SetMsgPid (nlmsg.GetHeader ().GetMsgPid ());
  24.530 +  rep.SetMsgSeq (nlmsg.GetHeader ().GetMsgSeq ());
  24.531 +  rep.SetMsgType (NETLINK_MSG_ERROR);
  24.532 +  rep.SetMsgFlags (0);
  24.533 +
  24.534 +  errmsg.SetError (err);
  24.535 +  //kernel send the whole nlmsg back if error != 0, here we just send the header back
  24.536 +  errmsg.SetMsg (nlmsg.GetHeader ());
  24.537 +
  24.538 +  //then send errmsg back to user space
  24.539 +  ackmsg.SetHeader (rep);
  24.540 +  ackmsg.SetErrorMessage (errmsg);
  24.541 +
  24.542 +  SendMessageUnicast (ackmsg, rep.GetMsgPid (), 1);
  24.543 +}
  24.544 +
  24.545 +int32_t
  24.546 +NetlinkSocket::HandleMessage (const NetlinkMessage&nlmsg)
  24.547 +{
  24.548 +  NS_LOG_FUNCTION (this);
  24.549 +  uint16_t type = nlmsg.GetMsgType ();
  24.550 +  NetlinkMessageHeader nhr = nlmsg.GetHeader ();
  24.551 +
  24.552 +  if (nhr.GetMsgLen () < NetlinkMessageHeader::GetHeaderSize ())
  24.553 +    {
  24.554 +      m_errno = ERROR_INVAL;
  24.555 +      return -1;
  24.556 +    }
  24.557 +
  24.558 +  if (NetlinkMessage::IsMessageNetlinkControl (type))
  24.559 +    {
  24.560 +      NS_LOG_INFO ("netlink control message type not parsed in kernel");
  24.561 +      return 0;
  24.562 +    }
  24.563 +  else if (NetlinkMessage::IsMessageNetlinkRoute (type))
  24.564 +    {
  24.565 +      return HandleNetlinkRouteMessage (nlmsg);
  24.566 +    }
  24.567 +  else
  24.568 +    {
  24.569 +      NS_LOG_INFO ("netlink message type not parsed in kernel");
  24.570 +      m_errno = ERROR_INVAL;
  24.571 +      return -1;
  24.572 +    }  
  24.573 +}
  24.574 +
  24.575 +int32_t
  24.576 +NetlinkSocket::HandleNetlinkRouteMessage (const NetlinkMessage &nlmsg)
  24.577 +{
  24.578 +  NS_LOG_FUNCTION (this);
  24.579 +  uint8_t family;
  24.580 +  int16_t type;
  24.581 +  int32_t err;
  24.582 +
  24.583 +  /* Only requests are handled by kernel now */
  24.584 +  if (!NetlinkMessage::IsMessageFlagsRequest (nlmsg.GetHeader ().GetMsgFlags ()))
  24.585 +    return 0;
  24.586 +
  24.587 +  type = nlmsg.GetMsgType ();
  24.588 +
  24.589 +  /* A control message: ignore them */
  24.590 +  if (NetlinkMessage::IsMessageNetlinkControl (type))
  24.591 +    {
  24.592 +      return 0;
  24.593 +    }
  24.594 +  else if (NetlinkMessage::IsMessageNetlinkRoute (type))
  24.595 +    {
  24.596 +      /* All the messages must have at least 1 byte length */
  24.597 +      if (nlmsg.GetPayloadSize () < 1)
  24.598 +        return 0;
  24.599 +
  24.600 +      family = nlmsg.GetFamily ();
  24.601 +      /*here we do not deal with different family, default for AF_NET*/
  24.602 +      NS_ASSERT(family == AF_INET || family == AF_UNSPEC || family == AF_PACKET || family == AF_INET6);  
  24.603 +
  24.604 +      /*for GET*** message, dump it to userspace*/
  24.605 +      if (NetlinkMessage::IsMessageTypeGet (type) && 
  24.606 +          NetlinkMessage::IsMessageFlagsDump (nlmsg.GetHeader ().GetMsgFlags ())) 
  24.607 +        {
  24.608 +          DumpNetlinkRouteMessage (nlmsg, type, family);
  24.609 +          return -1;
  24.610 +        }
  24.611 +
  24.612 +      /* other types of messages*/
  24.613 +      return DoNetlinkRouteMessage (nlmsg, type, family);
  24.614 +    }
  24.615 +  else/* Unknown message: reply with EINVAL */
  24.616 +    {
  24.617 +      err = ERROR_INVAL;
  24.618 +      return -1;
  24.619 +    } 
  24.620 +}
  24.621 +
  24.622 +int32_t
  24.623 +NetlinkSocket::DumpNetlinkRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  24.624 +{
  24.625 +  NS_LOG_FUNCTION (this << type << family);
  24.626 +
  24.627 +  NS_ASSERT (type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETLINK);
  24.628 +
  24.629 +  MultipartNetlinkMessage nlmsg_dump;
  24.630 +  NetlinkMessageHeader nhr = nlmsg.GetHeader ();
  24.631 +  int32_t err;
  24.632 +
  24.633 +  if (type == NETLINK_RTM_GETADDR)
  24.634 +    {
  24.635 +      nlmsg_dump = BuildInterfaceAddressDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);
  24.636 +    }
  24.637 +  else if (type == NETLINK_RTM_GETLINK)
  24.638 +    {
  24.639 +      nlmsg_dump = BuildInterfaceInfoDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);      
  24.640 +    }
  24.641 +  else if (type == NETLINK_RTM_GETROUTE)
  24.642 +    {
  24.643 +      nlmsg_dump = BuildRouteDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);
  24.644 +    }
  24.645 +  else
  24.646 +    {
  24.647 +      m_errno = ERROR_INVAL;
  24.648 +      return -1;
  24.649 +    }
  24.650 +
  24.651 +  //then append netlink message with type NLMSG_DONE
  24.652 +  NetlinkMessage nlmsg_done;
  24.653 +  NetlinkMessageHeader nhr2 = NetlinkMessageHeader (NETLINK_MSG_DONE, NETLINK_MSG_F_MULTI, 
  24.654 +                                                   nlmsg.GetHeader ().GetMsgSeq (), m_srcPid);
  24.655 +  nlmsg_done.SetHeader (nhr2);
  24.656 +  //kernel append nlmsg_dump size to it, here we omit it
  24.657 +  nlmsg_dump.AppendMessage (nlmsg_done);
  24.658 +
  24.659 +  err = SendMessageUnicast (nlmsg_dump, m_srcPid, 1);
  24.660 +  return err;
  24.661 +}
  24.662 +
  24.663 +/*here only for ADD/DEL/GET*** types*/
  24.664 +int32_t
  24.665 +NetlinkSocket::DoNetlinkRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  24.666 +{
  24.667 +  NS_LOG_FUNCTION (this << type <<family);
  24.668 +  int32_t err;
  24.669 +
  24.670 +  if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  24.671 +    {      
  24.672 +      err = DoInterfaceAddressMessage (nlmsg, type, family);
  24.673 +    }
  24.674 +  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  24.675 +    {     
  24.676 +      err = DoRouteMessage (nlmsg, type, family);
  24.677 +    }
  24.678 +  else if (type == NETLINK_RTM_GETLINK || type == NETLINK_RTM_SETLINK)
  24.679 +    {     
  24.680 +      err = DoInterfaceInfoMessage (nlmsg, type, family);
  24.681 +    }
  24.682 +  else
  24.683 +    {
  24.684 +      NS_LOG_LOGIC ("netlink message:type( " << type << ") not processed by ns3 now." );
  24.685 +      m_errno = ERROR_INVAL;
  24.686 +      err = -1;
  24.687 +    } 
  24.688 +  
  24.689 +  return err;
  24.690 +}
  24.691 +
  24.692 +MultipartNetlinkMessage
  24.693 +NetlinkSocket::BuildInterfaceAddressDumpMessage (uint32_t pid, uint32_t seq, uint8_t family)
  24.694 +{
  24.695 +  NS_LOG_FUNCTION (this << pid << seq <<family);
  24.696 +  MultipartNetlinkMessage nlmsg_dump;
  24.697 +  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
  24.698 +
  24.699 +  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++)
  24.700 +    {
  24.701 +      if (!ipv4->IsUp (i))
  24.702 +        continue;
  24.703 +
  24.704 +      Ipv4Address addri = ipv4->GetAddress (i, 0).GetLocal ();
  24.705 +      Ipv4Mask maski = ipv4->GetAddress (i, 0).GetMask ();
  24.706 +      Ipv4Address bcast = ipv4->GetAddress (i, 0).GetBroadcast ();
  24.707 +
  24.708 +      //here get the address mask length
  24.709 +      uint32_t mask = maski.Get ();
  24.710 +      uint8_t mask_len = 0;
  24.711 +      while (mask)
  24.712 +        {
  24.713 +          mask = mask << 1;
  24.714 +          mask_len ++;
  24.715 +        }
  24.716 +      
  24.717 +      //next fill the message body
  24.718 +      NetlinkMessage nlmsg_ifa;
  24.719 +      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWADDR, NETLINK_MSG_F_MULTI, seq, pid);
  24.720 +      InterfaceAddressMessage ifamsg;
  24.721 +
  24.722 +      ifamsg.SetInterfaceIndex (i);
  24.723 +      ifamsg.SetFamily (AF_INET);//default AF_INET      
  24.724 +      ifamsg.SetLength (mask_len);
  24.725 +      ifamsg.SetFlags (0);
  24.726 +      ifamsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  24.727 +
  24.728 +      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LOCAL,    ADDRESS, addri));
  24.729 +      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ADDRESS,  ADDRESS, addri));
  24.730 +      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_BROADCAST,ADDRESS, bcast));
  24.731 +      //      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LABEL,    STRING,  "ns3-ifaddr"));//not used in ns3
  24.732 +      //ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ANYCAST,  ADDRESS, Ipv4Address("0.0.0.0")));//not used in ns3
  24.733 +      //XXXother attributes not used by ns3
  24.734 +
  24.735 +      nlmsg_ifa.SetHeader(nhr);
  24.736 +      nlmsg_ifa.SetInterfaceAddressMessage (ifamsg);
  24.737 +      nlmsg_dump.AppendMessage (nlmsg_ifa);
  24.738 +    }
  24.739 +
  24.740 +  // For IPv6
  24.741 +  Ptr<Ipv6>ipv6 = m_node->GetObject<Ipv6> ();
  24.742 +
  24.743 +  for (uint32_t i = 0; i < ipv6->GetNInterfaces(); i ++)
  24.744 +    {
  24.745 +      if (!ipv6->IsUp (i))
  24.746 +        continue;
  24.747 +
  24.748 +      for (uint32_t j = 0; j < ipv6->GetNAddresses(i); j ++)
  24.749 +        {
  24.750 +          Ipv6Address addri = ipv6->GetAddress (i, j).GetAddress();
  24.751 +          Ipv6Prefix prefix = ipv6->GetAddress (i, j).GetPrefix ();
  24.752 +
  24.753 +          //here get the address mask length
  24.754 +          uint8_t mask_len = prefix.GetPrefixLength();
  24.755 +
  24.756 +          //loopback address's prefix is wrong... FIXME
  24.757 +          if (addri.IsEqual(Ipv6Address::GetLoopback()))
  24.758 +            mask_len = 128;
  24.759 +      
  24.760 +          //next fill the message body
  24.761 +          NetlinkMessage nlmsg_ifa;
  24.762 +          NetlinkMessageHeader nhr = NetlinkMessageHeader(NETLINK_RTM_NEWADDR, NETLINK_MSG_F_MULTI, seq, pid);
  24.763 +          InterfaceAddressMessage ifamsg;       
  24.764 +
  24.765 +          ifamsg.SetInterfaceIndex(i);
  24.766 +          ifamsg.SetFamily(AF_INET6);
  24.767 +          ifamsg.SetFlags(0);
  24.768 +
  24.769 +
  24.770 +          if (addri.IsLinkLocal())
  24.771 +            {
  24.772 +              ifamsg.SetLength(64);
  24.773 +              ifamsg.SetScope (RouteMessage::RT_SCOPE_LINK);
  24.774 +            }
  24.775 +          else
  24.776 +            {
  24.777 +              ifamsg.SetLength(mask_len);
  24.778 +              ifamsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  24.779 +            }
  24.780 +
  24.781 +
  24.782 +          ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LOCAL,    ADDRESS, addri));
  24.783 +          ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ADDRESS,  ADDRESS, addri));
  24.784 +          //XXXother attributes not used by ns3
  24.785 +
  24.786 +          nlmsg_ifa.SetHeader(nhr);
  24.787 +          nlmsg_ifa.SetInterfaceAddressMessage (ifamsg);
  24.788 +          nlmsg_dump.AppendMessage (nlmsg_ifa);
  24.789 +        }
  24.790 +    }
  24.791 +  return nlmsg_dump;
  24.792 +}
  24.793 +MultipartNetlinkMessage
  24.794 +NetlinkSocket::BuildInterfaceInfoDumpMessage (uint32_t pid, uint32_t seq, uint8_t family)
  24.795 +{
  24.796 +  NS_LOG_FUNCTION (this << pid << seq <<family);
  24.797 +  MultipartNetlinkMessage nlmsg_dump;
  24.798 +  for (uint32_t i = 0; i < m_node->GetNDevices (); i ++)
  24.799 +    {
  24.800 +      Ptr<NetDevice> dev = m_node->GetDevice (i);
  24.801 +      Address mac;
  24.802 +      Address bcast;
  24.803 +      uint32_t mtu;
  24.804 +      uint32_t flags = 0;
  24.805 +
  24.806 +      mac = dev->GetAddress ();
  24.807 +      bcast = dev->GetBroadcast ();
  24.808 +      mtu = (uint32_t)dev->GetMtu ();
  24.809 +
  24.810 +      if (dev->IsLinkUp ())
  24.811 +        {
  24.812 +          flags |= IFF_RUNNING;
  24.813 +          flags |= IFF_UP;
  24.814 +        }
  24.815 +      if (dev->IsBroadcast ())
  24.816 +        {
  24.817 +          flags |= IFF_BROADCAST;
  24.818 +        }
  24.819 +      if (dev->IsMulticast ())
  24.820 +        {
  24.821 +          flags |= IFF_MULTICAST;
  24.822 +        }
  24.823 +
  24.824 +      NetlinkMessage nlmsg_ifinfo;
  24.825 +      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWLINK, NETLINK_MSG_F_MULTI, seq, pid);
  24.826 +      InterfaceInfoMessage ifinfomsg;     
  24.827 +
  24.828 +      ifinfomsg.SetFamily(0);      // AF_UNSPEC
  24.829 +      ifinfomsg.SetDeviceType (0); // not clear
  24.830 +      ifinfomsg.SetInterfaceIndex (i);
  24.831 +      ifinfomsg.SetDeviceFlags (flags); // not clear
  24.832 +      ifinfomsg.SetChangeMask (0xffffffff);
  24.833 +
  24.834 +      // the ns3 device have no  name, here we set "ns3-device i" for test
  24.835 +      std::stringstream ss;
  24.836 +      ss <<  "ns3-device" << i;
  24.837 +
  24.838 +      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_IFNAME,    STRING,  ss.str()));
  24.839 +      //not used in ns3
  24.840 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_TXQLEN,    U32,     0));
  24.841 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_WEIGHT,    U32,     0));
  24.842 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_OPERSTATE, U8,      0));
  24.843 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_LINKMODE,  U8,      0));
  24.844 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_MAP,       UNSPEC,  0));
  24.845 +      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_ADDRESS,   ADDRESS, mac));
  24.846 +      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_BROADCAST, ADDRESS, bcast));
  24.847 +      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_MTU,       U32,     mtu));
  24.848 +      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_LINK,      U32,     i));
  24.849 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_QDISC,     STRING,  ""));
  24.850 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_MASTER,    U32,     0));
  24.851 +      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_STATS,     UNSPEC,  0));
  24.852 +
  24.853 +      nlmsg_ifinfo.SetHeader (nhr);
  24.854 +      nlmsg_ifinfo.SetInterfaceInfoMessage (ifinfomsg);
  24.855 +      nlmsg_dump.AppendMessage (nlmsg_ifinfo);
  24.856 +    }
  24.857 +  return nlmsg_dump;
  24.858 +}
  24.859 +MultipartNetlinkMessage
  24.860 +NetlinkSocket::BuildRouteDumpMessage (uint32_t pid, uint32_t seq, uint8_t family)
  24.861 +{
  24.862 +  NS_LOG_FUNCTION (this << pid << seq <<family);
  24.863 +  MultipartNetlinkMessage nlmsg_dump;
  24.864 +  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
  24.865 +
  24.866 +  // We only care about staticRouting for netlink support
  24.867 +  Ipv4StaticRoutingHelper routingHelper;
  24.868 +  Ptr<Ipv4StaticRouting> ipv4Static = routingHelper.GetStaticRouting (ipv4);
  24.869 +  for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); i ++)
  24.870 +    {
  24.871 +      NetlinkMessage nlmsg_rt;
  24.872 +      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, NETLINK_MSG_F_MULTI, seq, pid);
  24.873 +      RouteMessage rtmsg;
  24.874 +      Ipv4RoutingTableEntry route = ipv4Static->GetRoute (i);
  24.875 +
  24.876 +      rtmsg.SetFamily (AF_INET);
  24.877 +      rtmsg.SetDstLength (32);
  24.878 +      rtmsg.SetSrcLength (0);
  24.879 +      rtmsg.SetTos (0);//not clear
  24.880 +      rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
  24.881 +      rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  24.882 +      rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
  24.883 +      rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
  24.884 +
  24.885 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
  24.886 +      // ns3 use local address as the route src address
  24.887 +      //      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, route.GetSource()));
  24.888 +      //      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, route.GetSource()));//not used in ns3
  24.889 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface ()));
  24.890 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface ()));      
  24.891 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway ()));
  24.892 +
  24.893 +      nlmsg_rt.SetHeader (nhr);
  24.894 +      nlmsg_rt.SetRouteMessage (rtmsg);
  24.895 +      nlmsg_dump.AppendMessage (nlmsg_rt);
  24.896 +    }
  24.897 +
  24.898 +  Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
  24.899 +  // We only care about staticRouting for netlink support
  24.900 +  Ipv6StaticRoutingHelper routingHelper6;
  24.901 +  Ptr<Ipv6StaticRouting> ipv6Static = routingHelper6.GetStaticRouting (ipv6);
  24.902 +  for (uint32_t i = 0; i < ipv6Static->GetNRoutes (); i ++)
  24.903 +    {
  24.904 +      NetlinkMessage nlmsg_rt;
  24.905 +      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, NETLINK_MSG_F_MULTI, seq, pid);
  24.906 +      RouteMessage rtmsg;
  24.907 +      Ipv6RoutingTableEntry route = ipv6Static->GetRoute (i);
  24.908 +
  24.909 +      rtmsg.SetFamily (AF_INET6);
  24.910 +      rtmsg.SetDstLength (128);
  24.911 +      rtmsg.SetSrcLength (0);
  24.912 +      rtmsg.SetTos (0);//not clear
  24.913 +      rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
  24.914 +      rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  24.915 +      rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
  24.916 +      rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
  24.917 +
  24.918 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
  24.919 +      //ns3 use local address as the route src address
  24.920 +      // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, 
  24.921 +      //                                          ipv6->GetSourceAddress(route.GetDest ())));
  24.922 +      // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, 
  24.923 +      //                                          ipv6->GetSourceAddress(route.GetDest ())));
  24.924 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface()));
  24.925 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface()));      
  24.926 +      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway()));
  24.927 +
  24.928 +      nlmsg_rt.SetHeader (nhr);
  24.929 +      nlmsg_rt.SetRouteMessage (rtmsg);
  24.930 +      nlmsg_dump.AppendMessage (nlmsg_rt);
  24.931 +    }
  24.932 +
  24.933 +  return nlmsg_dump;
  24.934 +}
  24.935 +
  24.936 +int32_t
  24.937 +NetlinkSocket::DoInterfaceAddressMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  24.938 +{
  24.939 +  NS_LOG_FUNCTION (this << type << family);
  24.940 +  NS_ASSERT (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR);
  24.941 +
  24.942 +  // XXX
  24.943 +  NS_ASSERT_MSG (false, "Not implemented yet (RTM_NEWADDR/RTM_DELADDR)");
  24.944 +
  24.945 +  InterfaceAddressMessage ifamsg = nlmsg.GetInterfaceAddressMessage ();
  24.946 +  Ipv4Address addri, addr_local, bcast;
  24.947 +  NetlinkAttribute attr_local;
  24.948 +  uint32_t index = ifamsg.GetInterfaceIndex ();
  24.949 +  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
  24.950 +  int flag4 = 0, flag6 = 0;
  24.951 +
  24.952 +  if (type == NETLINK_RTM_NEWADDR)
  24.953 +    {
  24.954 +      //when adding an interface address, it should check the input arguments
  24.955 +      //prefix-len and local address attribute
  24.956 +      if (ifamsg.GetLength () > 32 || 
  24.957 +          ifamsg.GetAttributeByType (attr_local, InterfaceAddressMessage::IF_A_LOCAL) == false)
  24.958 +        {
  24.959 +          m_errno = ERROR_INVAL;
  24.960 +          return -1;
  24.961 +        }
  24.962 +    }  
  24.963 +
  24.964 +  //get necessary information for add/del, many attributes we not used
  24.965 +  for (uint32_t i = 0; i < ifamsg.GetNNetlinkAttribute (); i ++)
  24.966 +    {
  24.967 +      NetlinkAttribute attr = ifamsg.GetNetlinkAttribute (i);
  24.968 +      uint32_t attr_type = attr.GetAttrType ();
  24.969 +
  24.970 +      switch(attr_type)
  24.971 +        {
  24.972 +        case InterfaceAddressMessage::IF_A_ADDRESS:
  24.973 +          addri = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
  24.974 +          break;
  24.975 +        case InterfaceAddressMessage::IF_A_BROADCAST:
  24.976 +          bcast = Ipv4Address::ConvertFrom(attr.GetAttrPayload ().GetAddress ());
  24.977 +          break;
  24.978 +        case InterfaceAddressMessage::IF_A_LOCAL:
  24.979 +          addr_local = Ipv4Address::ConvertFrom(attr.GetAttrPayload ().GetAddress ());
  24.980 +          break;
  24.981 +        case InterfaceAddressMessage::IF_A_LABEL:
  24.982 +        case InterfaceAddressMessage::IF_A_ANYCAST:
  24.983 +          break;
  24.984 +        }
  24.985 +    }
  24.986 +
  24.987 +  if (type == NETLINK_RTM_NEWADDR)
  24.988 +    {
  24.989 +      //when adding an interface address by index, if the indexed interface was not exist,
  24.990 +      //create an new NetDevice with an new index and set the address
  24.991 +      //otherwise set the indexed interface directly
  24.992 +      if (index >= ipv4->GetNInterfaces ())
  24.993 +        {          
  24.994 +          Ptr<SimpleNetDevice> dev;
  24.995 +          dev = CreateObject<SimpleNetDevice> ();
  24.996 +          dev ->SetAddress (Mac48Address::Allocate ());
  24.997 +          m_node->AddDevice (dev);
  24.998 +
  24.999 +          uint32_t netdev_idx = ipv4->AddInterface (dev);
 24.1000 +          // FIXME!
 24.1001 +          Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (addri, Ipv4Mask ());
 24.1002 +          ipv4->AddAddress (netdev_idx, ipv4Addr);
 24.1003 +          ipv4->SetUp (netdev_idx);
 24.1004 +          NS_LOG_INFO ("Add an interface address at index "<< netdev_idx << "but not the ifamsg input" << index);
 24.1005 +        }
 24.1006 +      else
 24.1007 +        {
 24.1008 +          Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (addri, Ipv4Mask ());
 24.1009 +          ipv4->AddAddress (index, ipv4Addr);
 24.1010 +          if (!ipv4->IsUp (index))
 24.1011 +            ipv4->SetUp (index);
 24.1012 +        }    
 24.1013 +      flag4 = 1;
 24.1014 +    }
 24.1015 +  else//type == NETLINK_RTM_DELADDR
 24.1016 +    {
 24.1017 +      //when delete an interface address by index, if the indexed interface  was not exist
 24.1018 +      //return an error EINVAL, otherwise set down the interface which has the addri
 24.1019 +      if (index >= ipv4->GetNInterfaces ())
 24.1020 +        {
 24.1021 +          m_errno = ERROR_NODEV;
 24.1022 +          return -1;
 24.1023 +        }
 24.1024 +      else
 24.1025 +        {
 24.1026 +          for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++)
 24.1027 +            {
 24.1028 +              Ipv4Address ad = ipv4->GetAddress (i, 0).GetLocal ();
 24.1029 +              if (ad == addri && ipv4->IsUp (i))
 24.1030 +                {
 24.1031 +                  ipv4->SetDown (i);
 24.1032 +                  break;
 24.1033 +                }
 24.1034 +              if (i == ipv4->GetNInterfaces () - 1)
 24.1035 +                {
 24.1036 +                  m_errno = ERROR_ADDRNOTAVAIL;
 24.1037 +                  return -1;
 24.1038 +                }
 24.1039 +            }
 24.1040 +          flag4 = 1;
 24.1041 +        }      
 24.1042 +    }
 24.1043 +  
 24.1044 +  //then send an broadcast message, let all user know this operation happened
 24.1045 +  NetlinkMessage nlmsg_broadcast = nlmsg;
 24.1046 +  NetlinkMessageHeader nhr;
 24.1047 +  nhr.SetMsgLen (nlmsg.GetHeader ().GetMsgLen ());
 24.1048 +  nhr.SetMsgType (nlmsg.GetHeader ().GetMsgType ());
 24.1049 +  nlmsg_broadcast.SetHeader (nhr);
 24.1050 +  if (flag4)
 24.1051 +    {
 24.1052 +      SendMessageBroadcast (nlmsg_broadcast, 0, NETLINK_RTM_GRP_IPV4_IFADDR, GetNode ());
 24.1053 +    }
 24.1054 +  else if (flag6)
 24.1055 +    {
 24.1056 +      SendMessageBroadcast (nlmsg_broadcast, 0, RTMGRP_IPV6_IFADDR, GetNode ());
 24.1057 +    }
 24.1058 +
 24.1059 +  return 0;
 24.1060 +}
 24.1061 +
 24.1062 +int32_t
 24.1063 +NetlinkSocket::DoInterfaceInfoMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
 24.1064 +{
 24.1065 +  NS_LOG_FUNCTION (this << type << family);
 24.1066 +  NS_ASSERT (type == NETLINK_RTM_GETLINK || type == NETLINK_RTM_SETLINK);
 24.1067 +  InterfaceInfoMessage ifinfomsg = nlmsg.GetInterfaceInfoMessage ();
 24.1068 +  // XXX
 24.1069 +  NS_ASSERT_MSG (false, "Not implemented yet (RTM_GETLINK/RTM_SETLINK)");
 24.1070 +  return -1;
 24.1071 +}
 24.1072 +
 24.1073 +Address
 24.1074 +NetlinkSocket::ConvertFrom (uint8_t family, const Address &address)
 24.1075 +{
 24.1076 +  Address retval;
 24.1077 +  if (family == AF_INET)
 24.1078 +    {
 24.1079 +      retval = Ipv4Address::ConvertFrom (address);
 24.1080 +    }
 24.1081 +  else if (family == AF_INET6)
 24.1082 +    {
 24.1083 +      retval = Ipv6Address::ConvertFrom (address);
 24.1084 +    }
 24.1085 +  return retval;
 24.1086 +}
 24.1087 +
 24.1088 +int32_t
 24.1089 +NetlinkSocket::DoRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
 24.1090 +{
 24.1091 +  NS_LOG_FUNCTION (this << type << family);
 24.1092 +  NS_ASSERT (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE ||type == NETLINK_RTM_GETROUTE);
 24.1093 +
 24.1094 +  RouteMessage rtmsg = nlmsg.GetRouteMessage ();
 24.1095 +  Ipv4Address src, dest, gateway;
 24.1096 +  Ipv6Address src6, dest6, gateway6;
 24.1097 +  uint32_t index = 0;
 24.1098 +  int attr_flags[RouteMessage::RT_A_MAX] = {0};
 24.1099 +  uint8_t dstlen = rtmsg.GetDstLength ();
 24.1100 +
 24.1101 +  //get necessary information for add/del, many attributes we not used
 24.1102 +  for (uint32_t i = 0; i < rtmsg.GetNNetlinkAttribute (); i ++)
 24.1103 +    {
 24.1104 +      NetlinkAttribute attr = rtmsg.GetNetlinkAttribute (i);
 24.1105 +      uint32_t attr_type = attr.GetAttrType ();
 24.1106 +      attr_flags[attr_type] = 1;
 24.1107 +
 24.1108 +      switch(attr_type)
 24.1109 +        {
 24.1110 +        case RouteMessage::RT_A_DST:
 24.1111 +          if (family == AF_INET)
 24.1112 +            {
 24.1113 +              dest = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 24.1114 +            }
 24.1115 +          else if (family == AF_INET6)
 24.1116 +            {
 24.1117 +              dest6 = Ipv6Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 24.1118 +            }
 24.1119 +          break;
 24.1120 +        case RouteMessage::RT_A_SRC:
 24.1121 +          if (family == AF_INET)
 24.1122 +            {
 24.1123 +              src = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 24.1124 +            }
 24.1125 +          else if (family == AF_INET6)
 24.1126 +            {
 24.1127 +              src6 = Ipv6Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 24.1128 +            }
 24.1129 +          break;
 24.1130 +        case RouteMessage::RT_A_OIF:
 24.1131 +          index = attr.GetAttrPayload ().GetU32 ();
 24.1132 +          break;
 24.1133 +        case RouteMessage::RT_A_GATEWAY:
 24.1134 +          if (family == AF_INET)
 24.1135 +            {
 24.1136 +              gateway = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 24.1137 +            }
 24.1138 +          else if (family == AF_INET6)
 24.1139 +            {
 24.1140 +              gateway6 = Ipv6Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 24.1141 +            }
 24.1142 +          break;
 24.1143 +        case RouteMessage::RT_A_IIF:
 24.1144 +        case RouteMessage::RT_A_PRIORITY:
 24.1145 +        case RouteMessage::RT_A_PREFSRC:
 24.1146 +        case RouteMessage::RT_A_METRICS:
 24.1147 +        case RouteMessage::RT_A_MULTIPATH:
 24.1148 +        case RouteMessage::RT_A_PROTOINFO:
 24.1149 +        case RouteMessage::RT_A_FLOW:
 24.1150 +        case RouteMessage::RT_A_CACHEINFO:
 24.1151 +        case RouteMessage::RT_A_SESSION:
 24.1152 +        case RouteMessage::RT_A_MP_ALGO:
 24.1153 +        case RouteMessage::RT_A_TABLE:
 24.1154 +          NS_LOG_INFO("route attribute not used by ns3" << attr_type);
 24.1155 +          //not used by ns3
 24.1156 +          break;
 24.1157 +        }
 24.1158 +    }
 24.1159 +
 24.1160 +  // Sigh....
 24.1161 +  Ptr<Ipv4>ipv4 = m_node->GetObject<Ipv4> ();
 24.1162 +  Ipv4StaticRoutingHelper routingHelper;
 24.1163 +  Ptr<Ipv4StaticRouting> ipv4Static = routingHelper.GetStaticRouting (ipv4);
 24.1164 +
 24.1165 +  Ptr<Ipv6>ipv6 = m_node->GetObject<Ipv6> ();
 24.1166 +  Ipv6StaticRoutingHelper routingHelper6;
 24.1167 +  Ptr<Ipv6StaticRouting> ipv6Static = routingHelper6.GetStaticRouting (ipv6);
 24.1168 +
 24.1169 +  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Route message, type: " << type << "; from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 24.1170 +      << " to " << dest<< " through " << gateway);
 24.1171 +
 24.1172 +  if (type == NETLINK_RTM_NEWROUTE)
 24.1173 +    {
 24.1174 +      //ns3 add a route entry only depends on 2 or 3 attribute
 24.1175 +      //other route msg attibute were ignored
 24.1176 +      if (attr_flags[RouteMessage::RT_A_DST])
 24.1177 +        {
 24.1178 +          if (family == AF_INET)
 24.1179 +            {
 24.1180 +              if (!attr_flags[RouteMessage::RT_A_OIF])
 24.1181 +                {
 24.1182 +                  bool found = 0;
 24.1183 +                  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
 24.1184 +                    {
 24.1185 +                      for (uint32_t j = 0; j < ipv4->GetNAddresses (i); j++)
 24.1186 +                        {
 24.1187 +                          if ((attr_flags[RouteMessage::RT_A_GATEWAY]))
 24.1188 +                            {
 24.1189 +                              Ipv4Mask mask = ipv4->GetAddress (i, j).GetMask ();
 24.1190 +                              if (mask.IsMatch (ipv4->GetAddress (i, j).GetLocal (), gateway))
 24.1191 +                                {
 24.1192 +                                  index = i;
 24.1193 +                                  found = true;
 24.1194 +                                  break;
 24.1195 +                                }
 24.1196 +                            }
 24.1197 +                          if (found) break;
 24.1198 +                        }
 24.1199 +                    }
 24.1200 +                  if (!found)
 24.1201 +                    {
 24.1202 +                      NS_LOG_DEBUG ("No suitable interface to add an route entry");
 24.1203 +                      m_errno = ERROR_ADDRNOTAVAIL;
 24.1204 +                      return -1;
 24.1205 +                    }
 24.1206 +                }
 24.1207 +            if (dstlen == 32)
 24.1208 +              {
 24.1209 +                int exist_flag = 0;
 24.1210 +                for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); ++i)
 24.1211 +                  {
 24.1212 +                    Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 24.1213 +                    if (dest == rt.GetDest ())
 24.1214 +                      {
 24.1215 +                        exist_flag = 1;
 24.1216 +                      }
 24.1217 +                  }
 24.1218 +
 24.1219 +                if (exist_flag)
 24.1220 +                  { //route to dest already exists
 24.1221 +                    int delete_flag = 0;
 24.1222 +                    if (nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_REPLACE)
 24.1223 +                      {
 24.1224 +                        for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); ++i)
 24.1225 +                          {
 24.1226 +                            Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 24.1227 +                            if (dest == rt.GetDest ())
 24.1228 +                              {
 24.1229 +                                ipv4Static->RemoveRoute (i);
 24.1230 +                                NS_LOG_DEBUG ("Route from  " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << " to "
 24.1231 +                                    << dest << " through " << gateway << " removed");
 24.1232 +                                delete_flag = 1;
 24.1233 +                              }
 24.1234 +                          }
 24.1235 +
 24.1236 +                        if (!delete_flag)
 24.1237 +                          {
 24.1238 +                             NS_LOG_INFO ("no route entry removed by dest address in new route sector " << dest);
 24.1239 +                             m_errno = ERROR_INVAL;
 24.1240 +                             return -1;
 24.1241 +                           }
 24.1242 +                      }
 24.1243 +                    else
 24.1244 +                      {
 24.1245 +                        NS_LOG_DEBUG ("Route exists but overwriting declined!");
 24.1246 +                      }
 24.1247 +                    if ((attr_flags[RouteMessage::RT_A_GATEWAY]))
 24.1248 +                      {
 24.1249 +                        NS_LOG_DEBUG (Simulator::Now().GetSeconds() << "Overwrite route from "
 24.1250 +                            << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << " to " << dest<< " through " << gateway << " with index" << index);
 24.1251 +                        ipv4Static->AddHostRouteTo (dest, gateway, index);
 24.1252 +                      }
 24.1253 +                    else
 24.1254 +                      {
 24.1255 +                        NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Overwrite route from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 24.1256 +                            << " to " << dest<< " through " << "self" << " with index" << index);
 24.1257 +                        ipv4Static->AddHostRouteTo (dest, index);
 24.1258 +                      }
 24.1259 +                }
 24.1260 +                else
 24.1261 +                  { //route to dest doesn't exist
 24.1262 +                    if (nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_CREATE)
 24.1263 +                      {
 24.1264 +                        if (attr_flags[RouteMessage::RT_A_GATEWAY])
 24.1265 +                          {
 24.1266 +                            NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Add new route from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 24.1267 +                                << " to " << dest<< " through " << gateway << " with index" << index);
 24.1268 +                            ipv4Static->AddHostRouteTo (dest, gateway, index);
 24.1269 +                          }
 24.1270 +                        else
 24.1271 +                          {
 24.1272 +                            NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Add new route from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 24.1273 +                                << " to " << dest<< " through " << "self" << " with index" << index);
 24.1274 +                            ipv4Static->AddHostRouteTo (dest, index);
 24.1275 +                          }
 24.1276 +                      }
 24.1277 +                    else
 24.1278 +                      {
 24.1279 +                        NS_LOG_ERROR ("Route doesn't exist but writing declined!");
 24.1280 +                      }
 24.1281 +                  }
 24.1282 +
 24.1283 +                NS_LOG_DEBUG ("=After change attempt=");
 24.1284 +                //Dump of table
 24.1285 +                NS_LOG_DEBUG (m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << ":");
 24.1286 +                for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); ++i)
 24.1287 +                  {
 24.1288 +                    Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 24.1289 +                    NS_LOG_DEBUG (rt.GetDest () << " through " << rt.GetGateway ());
 24.1290 +                  }
 24.1291 +                NS_LOG_DEBUG ("= = = = = = = = = = =");
 24.1292 +              }
 24.1293 +            else // dstlen != 32
 24.1294 +              {
 24.1295 +                if (attr_flags[RouteMessage::RT_A_GATEWAY])
 24.1296 +                  {
 24.1297 +                    ipv4Static->AddNetworkRouteTo (dest, Ipv4Mask (~(1<<(32 - dstlen))+1), gateway, index);
 24.1298 +                  }
 24.1299 +                else
 24.1300 +                  {
 24.1301 +                    ipv4Static->AddNetworkRouteTo (dest, Ipv4Mask (~(1<<(32 - dstlen))+1), index);
 24.1302 +                  }
 24.1303 +              }
 24.1304 +          }
 24.1305 +          else if (family == AF_INET6)
 24.1306 +            {
 24.1307 +            if (!attr_flags[RouteMessage::RT_A_OIF])
 24.1308 +              {
 24.1309 +#ifdef FIXME
 24.1310 +              if (ipv6->GetIfIndexForDestination (gateway6, index) == false)
 24.1311 +                {
 24.1312 +                  NS_LOG_INFO ("No suitable interface to add an route entry");
 24.1313 +                  m_errno = ERROR_ADDRNOTAVAIL;
 24.1314 +                  return -1;
 24.1315 +                }
 24.1316 +#endif
 24.1317 +              }
 24.1318 +
 24.1319 +            Ipv6Prefix pref (dstlen);
 24.1320 +            if (attr_flags[RouteMessage::RT_A_GATEWAY])
 24.1321 +              {
 24.1322 +                ipv6Static->AddNetworkRouteTo (dest6, pref, gateway6, index);
 24.1323 +              }
 24.1324 +            else
 24.1325 +              {
 24.1326 +                ipv6Static->AddNetworkRouteTo (dest6, pref, Ipv6Address("::"), index);
 24.1327 +              }
 24.1328 +            }
 24.1329 +          }
 24.1330 +        else
 24.1331 +          {
 24.1332 +            NS_LOG_INFO("too few attributes to add an route entry");
 24.1333 +            m_errno = ERROR_INVAL;
 24.1334 +            return -1;
 24.1335 +          }
 24.1336 +    }
 24.1337 +  else if (type == NETLINK_RTM_DELROUTE)
 24.1338 +    {
 24.1339 +      NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Route delete request from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 24.1340 +          << " to " << dest<< " through " << gateway);
 24.1341 +      if (attr_flags[RouteMessage::RT_A_DST])
 24.1342 +        {
 24.1343 +          int delete_flag = 0;
 24.1344 +
 24.1345 +          if (family == AF_INET)
 24.1346 +            {
 24.1347 +              for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); i ++)
 24.1348 +                {
 24.1349 +                Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 24.1350 +                if (gateway == rt.GetGateway () && dest == rt.GetDest ())
 24.1351 +                  {
 24.1352 +                    ipv4Static->RemoveRoute (i);
 24.1353 +                    delete_flag = 1;
 24.1354 +                  }
 24.1355 +                }
 24.1356 +            }
 24.1357 +          else if (family == AF_INET6)
 24.1358 +            {
 24.1359 +              for (uint32_t i = 0; i < ipv6Static->GetNRoutes (); i ++)
 24.1360 +                {
 24.1361 +                Ipv6RoutingTableEntry rt = ipv6Static->GetRoute (i);
 24.1362 +                if (gateway6 == rt.GetGateway () && dest6 == rt.GetDest ())
 24.1363 +                  {
 24.1364 +                    ipv6Static->RemoveRoute (i);
 24.1365 +                    delete_flag = 1;
 24.1366 +                  }
 24.1367 +                }
 24.1368 +            }
 24.1369 +
 24.1370 +          if (!delete_flag)
 24.1371 +            {
 24.1372 +              NS_LOG_INFO ("no route entry removed by dest address " << dest);
 24.1373 +              m_errno = ERROR_INVAL;
 24.1374 +              return -1;
 24.1375 +            }
 24.1376 +        }
 24.1377 +      else
 24.1378 +        {
 24.1379 +          NS_LOG_INFO ("too few attributes to add an route entry");
 24.1380 +          m_errno = ERROR_INVAL;
 24.1381 +          return -1;    
 24.1382 +        }
 24.1383 +    }
 24.1384 +  else// type == NETLINK_RTM_GETROUTE
 24.1385 +    {
 24.1386 +      NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "GetRoute "<< "from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << " to " << dest);
 24.1387 +      if (!attr_flags[RouteMessage::RT_A_DST])
 24.1388 +        {
 24.1389 +          NS_LOG_INFO ("too few attributes to get an route entry");
 24.1390 +          m_errno = ERROR_INVAL;
 24.1391 +          return -1;
 24.1392 +        }
 24.1393 +      
 24.1394 +      int get_flag = 0;
 24.1395 +      if (family == AF_INET)
 24.1396 +        {
 24.1397 +          for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); i ++)
 24.1398 +            {
 24.1399 +              Ipv4RoutingTableEntry route = ipv4Static->GetRoute (i);
 24.1400 +              //find the route entry with same dest address and send unicast to user space
 24.1401 +              if (dest.IsEqual (route.GetDest ()))
 24.1402 +                {
 24.1403 +                  //                Ptr<Ipv4>ipv4 = m_node->GetObject<Ipv4> ();
 24.1404 +                  NetlinkMessage nlmsg_route;
 24.1405 +                  NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, 0, 
 24.1406 +                                                                   nlmsg.GetHeader ().GetMsgSeq (), m_srcPid);
 24.1407 +                  RouteMessage rtmsg;
 24.1408 +
 24.1409 +                  //fill rtmsg and attributes
 24.1410 +                  rtmsg.SetFamily (AF_INET);
 24.1411 +                  rtmsg.SetDstLength (32);
 24.1412 +                  rtmsg.SetSrcLength (0);
 24.1413 +                  rtmsg.SetTos (0);//not clear
 24.1414 +                  rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
 24.1415 +                  rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
 24.1416 +                  rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
 24.1417 +                  rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
 24.1418 +
 24.1419 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
 24.1420 +                  //ns3 use local address as the route src address
 24.1421 +                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, ipv4->GetSourceAddress(route.GetDest ())));
 24.1422 +                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, ipv4->GetSourceAddress(route.GetDest ())));
 24.1423 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface ()));
 24.1424 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface ()));
 24.1425 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway ()));
 24.1426 +
 24.1427 +                  //fill an netlink message body
 24.1428 +                  nlmsg_route.SetHeader (nhr);
 24.1429 +                  nlmsg_route.SetRouteMessage (rtmsg);
 24.1430 +                  
 24.1431 +                  SendMessageUnicast (nlmsg_route, m_srcPid, 1);
 24.1432 +                  get_flag = 1;
 24.1433 +                }
 24.1434 +            }
 24.1435 +        }
 24.1436 +      else if (family == AF_INET6)
 24.1437 +        {
 24.1438 +          for (uint32_t i = 0; i < ipv6Static->GetNRoutes(); i ++)
 24.1439 +            {
 24.1440 +              Ipv6RoutingTableEntry route = ipv6Static->GetRoute (i);
 24.1441 +              //find the route entry with same dest address and send unicast to user space
 24.1442 +              if (dest6.IsEqual (route.GetDest ()))
 24.1443 +                {
 24.1444 +                  NetlinkMessage nlmsg_route;
 24.1445 +                  NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, 0, 
 24.1446 +                                                                   nlmsg.GetHeader ().GetMsgSeq (), m_srcPid);
 24.1447 +                  RouteMessage rtmsg;
 24.1448 +
 24.1449 +                  //fill rtmsg and attributes
 24.1450 +                  rtmsg.SetFamily (AF_INET6);
 24.1451 +                  rtmsg.SetDstLength (32);
 24.1452 +                  rtmsg.SetSrcLength (0);
 24.1453 +                  rtmsg.SetTos (0);//not clear
 24.1454 +                  rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
 24.1455 +                  rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
 24.1456 +                  rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
 24.1457 +                  rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
 24.1458 +
 24.1459 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
 24.1460 +                  //ns3 use local address as the route src address
 24.1461 +                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, ipv6->GetSourceAddress(route.GetDest ())));
 24.1462 +                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, ipv6->GetSourceAddress(route.GetDest ())));
 24.1463 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface ()));
 24.1464 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface ()));
 24.1465 +                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway ()));
 24.1466 +
 24.1467 +                  //fill an netlink message body
 24.1468 +                  nlmsg_route.SetHeader (nhr);
 24.1469 +                  nlmsg_route.SetRouteMessage (rtmsg);
 24.1470 +
 24.1471 +                  SendMessageUnicast (nlmsg_route, m_srcPid, 1);
 24.1472 +                  get_flag = 1;
 24.1473 +                }
 24.1474 +            }
 24.1475 +        }
 24.1476 +      
 24.1477 +      if (!get_flag)
 24.1478 +        {
 24.1479 +          NS_LOG_INFO ("no route entry exist by dest address" << dest);
 24.1480 +          m_errno = ERROR_INVAL;
 24.1481 +          return -1;
 24.1482 +        }
 24.1483 +    }
 24.1484 +
 24.1485 +  //then send an broadcast message, let all user know this operation happened
 24.1486 +  MultipartNetlinkMessage nlmsg_multi;
 24.1487 +  NetlinkMessage nlmsg_broadcast = nlmsg;
 24.1488 +  NetlinkMessage nlmsg_done;
 24.1489 +  NetlinkMessageHeader nhr_done = NetlinkMessageHeader (NETLINK_MSG_DONE, NETLINK_MSG_F_MULTI, 0, 0);
 24.1490 +  nlmsg_done.SetHeader (nhr_done);
 24.1491 +  nlmsg_multi.AppendMessage (nlmsg);
 24.1492 +  nlmsg_multi.AppendMessage (nlmsg_done);
 24.1493 +  SendMessageBroadcast (nlmsg_multi, 0, NETLINK_RTM_GRP_IPV4_ROUTE, GetNode ());
 24.1494 +  //   SendMessageBroadcast(nlmsg_broadcast, 0, RTMGRP_IPV6_ROUTE);
 24.1495 +  return 0;
 24.1496 +}
 24.1497 +
 24.1498 +int32_t
 24.1499 +NetlinkSocket::NotifyIfLinkMessage (Address address, uint16_t type, uint8_t family)
 24.1500 +{
 24.1501 +  NS_ASSERT_MSG (false, "Not implemented yet (NotifyIfLinkMessage)");
 24.1502 +  return 0;
 24.1503 +}
 24.1504 +
 24.1505 +int32_t
 24.1506 +NetlinkSocket::NotifyIfAddrMessage (Ipv6Interface* interface, Ipv6Address addr, int cmd)
 24.1507 +{
 24.1508 +  MultipartNetlinkMessage nlmsg_multi;
 24.1509 +  NetlinkMessage nlmsg_ifa;
 24.1510 +  NetlinkMessageHeader nhr = NetlinkMessageHeader (cmd, NETLINK_MSG_F_MULTI, 0, 0);
 24.1511 +  InterfaceAddressMessage ifamsg;
 24.1512 +
 24.1513 +  NS_ASSERT_MSG (false, "Not implemented yet (NotifyIfAddrMessage)");
 24.1514 +
 24.1515 +  // FIXME!
 24.1516 +  Ipv6Prefix prefix = Ipv6Prefix(64);
 24.1517 +
 24.1518 +  //here get the address mask length
 24.1519 +  uint8_t bytes[16];
 24.1520 +  prefix.GetBytes (bytes);
 24.1521 +  uint8_t mask_len = 0;
 24.1522 +  for (int j = 0; j < 16; j++)
 24.1523 +    {
 24.1524 +      while (bytes[j])
 24.1525 +        {
 24.1526 +          bytes[j] = bytes[j] << 1;
 24.1527 +          mask_len ++;
 24.1528 +        }
 24.1529 +    }
 24.1530 +      
 24.1531 +  ifamsg.SetInterfaceIndex (interface->GetDevice ()->GetIfIndex ());
 24.1532 +  ifamsg.SetFamily (AF_INET6);
 24.1533 +  ifamsg.SetLength (mask_len);
 24.1534 +  ifamsg.SetFlags (0);
 24.1535 +  ifamsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
 24.1536 +
 24.1537 +  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LOCAL,    ADDRESS, addr));
 24.1538 +  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ADDRESS,  ADDRESS, addr));
 24.1539 +  //  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_BROADCAST,ADDRESS, bcast));
 24.1540 +  //      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LABEL,    STRING,  "ns3-ifaddr"));//not used in ns3
 24.1541 +  //ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ANYCAST,  ADDRESS, Ipv4Address("0.0.0.0")));//not used in ns3
 24.1542 +  //XXXother attributes not used by ns3
 24.1543 +
 24.1544 +  nlmsg_ifa.SetHeader (nhr);
 24.1545 +  nlmsg_ifa.SetInterfaceAddressMessage (ifamsg);
 24.1546 +
 24.1547 +  NetlinkMessage nlmsg_done;
 24.1548 +  NetlinkMessageHeader nhr_done = NetlinkMessageHeader (NETLINK_MSG_DONE, NETLINK_MSG_F_MULTI, 0, 0);
 24.1549 +  nlmsg_done.SetHeader (nhr_done);
 24.1550 +
 24.1551 +  nlmsg_multi.AppendMessage (nlmsg_ifa);
 24.1552 +  nlmsg_multi.AppendMessage (nlmsg_done);
 24.1553 +
 24.1554 +  SendMessageBroadcast (nlmsg_multi, 0, RTMGRP_IPV6_IFADDR, interface->GetDevice ()->GetNode ());  
 24.1555 +  return 0;
 24.1556 +}
 24.1557 +
 24.1558 +#ifdef FIXME
 24.1559 +int32_t
 24.1560 +NetlinkSocket::NotifyRouteMessage(Ojbect route, uint16_t type, uint8_t family)
 24.1561 +{
 24.1562 +  NetlinkMessage nlmsg_broadcast = nlmsg;
 24.1563 +  NetlinkMessageHeader nhr;
 24.1564 +  NS_ASSERT_MSG (false, "Not implemented yet");
 24.1565 +
 24.1566 +  nhr.SetMsgLen (nlmsg.GetHeader ().GetMsgLen ());
 24.1567 +  nhr.SetMsgType (nlmsg.GetHeader ().GetMsgType ());
 24.1568 +  nlmsg_broadcast.SetHeader (nhr);
 24.1569 +  SendMessageBroadcast (nlmsg_broadcast, 0, RTMGRP_IPV6_ROUTE);
 24.1570 +  return 0;
 24.1571 +}
 24.1572 +#endif
 24.1573 +
 24.1574 +}//namespace ns3
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/model/netlink-socket.h	Mon Apr 18 12:13:02 2011 +0200
    25.3 @@ -0,0 +1,205 @@
    25.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    25.5 +/*
    25.6 + * Copyright (c) 2008 Liu Jian
    25.7 + *
    25.8 + * This program is free software; you can redistribute it and/or modify
    25.9 + * it under the terms of the GNU General Public License version 2 as
   25.10 + * published by the Free Software Foundation;
   25.11 + *
   25.12 + * This program is distributed in the hope that it will be useful,
   25.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   25.15 + * GNU General Public License for more details.
   25.16 + *
   25.17 + * You should have received a copy of the GNU General Public License
   25.18 + * along with this program; if not, write to the Free Software
   25.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25.20 + *
   25.21 + * Author: Liu Jian <liujatp@gmail.com>
   25.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   25.23 + */
   25.24 +#ifndef NETLINK_SOCKET_H
   25.25 +#define NETLINK_SOCKET_H
   25.26 +
   25.27 +#include <stdint.h>
   25.28 +#include <queue>
   25.29 +#include "netlink-message.h"
   25.30 +#include "ns3/callback.h"
   25.31 +#include "ns3/ptr.h"
   25.32 +#include "ns3/traced-callback.h"
   25.33 +#include "ns3/socket.h"
   25.34 +#include "ns3/ipv4-address.h"
   25.35 +#include "ns3/ipv6-address.h"
   25.36 +#include "ns3/ipv6-interface.h"
   25.37 +
   25.38 +namespace ns3 {
   25.39 +
   25.40 +class Node;
   25.41 +class Packet;
   25.42 +class NetlinkSocketAddress;
   25.43 +
   25.44 +/**
   25.45 +* \brief A NetlinkSocket is  used  to transfer information 
   25.46 +between kernel and userspace processes .
   25.47 +*
   25.48 +* here we focus on NETLINK_ROUTE: Receives routing and link
   25.49 +* updates and may be used to modify  the  routing  tables 
   25.50 +* (both IPv4 and IPv6), IP addresses, link parame- ters, neighbor
   25.51 +* setups, queueing disciplines, traffic classes and packet 
   25.52 +* classifiers (see rtnetlink (7)). This socket type is very similar
   25.53 +* to the linux and BSD "packet" sockets.
   25.54 +*
   25.55 +* Here is a summary of the semantics of this class:
   25.56 +* - Bind: Bind uses only the protocol and device fields of the 
   25.57 +*       NetlinkSocketAddress.
   25.58 +*
   25.59 +* - Send: send the input packet to the underlying kernel space
   25.60 +*       with its own address. The socket must  be bound.
   25.61 +*
   25.62 +* - Recv: receive packet from the kernel space.
   25.63 +*
   25.64 +* - Accept: not allowed
   25.65 +* - Connect: not allowed
   25.66 +*/
   25.67 +class NetlinkSocket : public Socket
   25.68 +{
   25.69 +public:
   25.70 +  static TypeId GetTypeId (void);
   25.71 +
   25.72 +  NetlinkSocket ();
   25.73 +  virtual ~NetlinkSocket ();
   25.74 +
   25.75 +  void SetNode (Ptr<Node> node);
   25.76 +
   25.77 +  virtual enum SocketErrno GetErrno (void) const;
   25.78 +  virtual enum Socket::SocketType GetSocketType (void) const;
   25.79 +  virtual Ptr<Node> GetNode (void) const;
   25.80 +  virtual int Bind (void);
   25.81 +  virtual int Bind (const Address & address);
   25.82 +  virtual int Close (void);
   25.83 +  virtual int ShutdownSend (void);
   25.84 +  virtual int ShutdownRecv (void);
   25.85 +  virtual int Connect (const Address &address);
   25.86 +  virtual int Listen (void);
   25.87 +  virtual uint32_t GetTxAvailable (void) const;
   25.88 +  virtual int Send (Ptr<Packet> p, uint32_t flags);
   25.89 +  virtual int SendTo(Ptr<Packet> p, uint32_t flags, const Address &toAddress);
   25.90 +  virtual uint32_t GetRxAvailable (void) const;
   25.91 +  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
   25.92 +  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, 
   25.93 +                                Address &fromAddress);
   25.94 +  virtual int GetSockName (Address &address) const; 
   25.95 +  virtual int GetPeerName (Address &address) const;
   25.96 +  virtual bool SetAllowBroadcast (bool allowBroadcast);
   25.97 +  virtual bool GetAllowBroadcast () const;
   25.98 +
   25.99 +  uint32_t GetSrcPid (void) const;
  25.100 +  uint32_t GetSrcGroups (void)const;
  25.101 +  uint32_t GetDstPid (void) const;
  25.102 +  uint32_t GetDstGroups (void)const;
  25.103 +  int32_t NotifyIfAddrMessage (Ipv6Interface* interface, Ipv6Address addr, int cmd);
  25.104 +  int32_t NotifyIfLinkMessage (Address address, uint16_t type, uint8_t family);
  25.105 +  //  int32_t NotifyRouteMessage(Ojbect route, uint16_t type, uint8_t family);
  25.106 +
  25.107 +private:
  25.108 +  int DoBind (const NetlinkSocketAddress &address);
  25.109 +  virtual void DoDispose (void);
  25.110 +  void ForwardUp (Ptr<Packet> p, NetlinkSocketAddress &address);
  25.111 +
  25.112 +
  25.113 +
  25.114 +  /**
  25.115 + * the functions below were for kernel parsing netlink message,set private here
  25.116 + * when netlink msg sent to kernel through netlink socket, it was parsed in kernel
  25.117 + * space, then, kernel add/del its route/interface/link table or dump all information
  25.118 + * to user space
  25.119 + */
  25.120 +
  25.121 +  int32_t HandleMessage (const NetlinkMessage &nlmsg);
  25.122 +  /**
  25.123 +  * when kernel find the message truncated or user need an ACK response,
  25.124 +  * it send ACK back to user space, with the error code(0 for ACK, > 0 for error).
  25.125 +  */
  25.126 +  void SendAckMessage (const NetlinkMessage &nlmsg, int32_t errorcode);
  25.127 +
  25.128 +  /**
  25.129 +  * \brief unicast an message to user
  25.130 +  * \param nlmsg the netlink message to transmit
  25.131 +  * \param pid the netlink pid of destination socket
  25.132 +  * \param nonbloack always true
  25.133 +  */
  25.134 +  int32_t SendMessageUnicast (const MultipartNetlinkMessage &nlmsg, 
  25.135 +                              uint32_t pid, int32_t nonblock);
  25.136 +  /**
  25.137 +  * \brief spread message to netlink group user
  25.138 +  * \param nlmsg the netlink message to transmit
  25.139 +  * \param pid the netlink pid of the kernel, always 0
  25.140 +  * \param group multicast group id
  25.141 +  */
  25.142 +  static int32_t SendMessageBroadcast (const MultipartNetlinkMessage &nlmsg, 
  25.143 +                                       uint32_t pid, uint32_t group, Ptr<Node> node);
  25.144 +
  25.145 +  /**
  25.146 +  * these functions below are for NETLINK_ROUTE protocol, it handle the netlink 
  25.147 +  * message like linux kernel work.  this implementation follows the kernel code 
  25.148 +  * linux/rtnetlink.c, focus on "interface address, interface info and route entry",
  25.149 +  * now we will only simply support three types operations of  NETLINK_ROUTE 
  25.150 +  * protocol
  25.151 +  */
  25.152 +  
  25.153 +  /**
  25.154 +  * \returns 0 if messge not processed, < 0 for success or an error.
  25.155 +  * this function would call dumping/doing functions to  
  25.156 +  */
  25.157 +  int32_t HandleNetlinkRouteMessage (const NetlinkMessage &nlmsg);
  25.158 +  
  25.159 +  /**
  25.160 +  * \returns 0 if dumping operation is OK, < 0 for an error.
  25.161 +  */ 
  25.162 +  int32_t DumpNetlinkRouteMessage (const NetlinkMessage &nlmsg, 
  25.163 +                                   uint16_t type, uint8_t family);
  25.164 +  MultipartNetlinkMessage BuildInterfaceAddressDumpMessage (uint32_t pid,
  25.165 +                                                            uint32_t seq, uint8_t family);
  25.166 +  MultipartNetlinkMessage BuildInterfaceInfoDumpMessage (uint32_t pid,
  25.167 +                                                         uint32_t seq, uint8_t family);
  25.168 +  MultipartNetlinkMessage BuildRouteDumpMessage (uint32_t pid,
  25.169 +                                                 uint32_t seq, uint8_t family);
  25.170 +
  25.171 +  /**
  25.172 +  * \returns 0 if doing operation(ADD/DEL/GET) is OK, < 0 for an error.
  25.173 +  */
  25.174 +  int32_t DoNetlinkRouteMessage (const NetlinkMessage &nlmsg,
  25.175 +                                 uint16_t type, uint8_t family);
  25.176 +  int32_t DoInterfaceAddressMessage (const NetlinkMessage &nlmsg, 
  25.177 +                                     uint16_t type, uint8_t family);
  25.178 +  int32_t DoInterfaceInfoMessage (const NetlinkMessage &nlmsg, 
  25.179 +                                  uint16_t type, uint8_t family);
  25.180 +  int32_t DoRouteMessage (const NetlinkMessage &nlmsg, 
  25.181 +                          uint16_t type, uint8_t family);
  25.182 +
  25.183 +  int ErrnoToSimuErrno (void);
  25.184 +  Address ConvertFrom (uint8_t family, const Address &address);
  25.185 +
  25.186 +  Ptr<Node> m_node;
  25.187 +  enum SocketErrno m_errno;
  25.188 +  bool m_shutdownSend;
  25.189 +  bool m_shutdownRecv;
  25.190 +
  25.191 +  std::queue<Ptr<Packet> > m_dataReceiveQueue;
  25.192 +  uint32_t m_rxAvailable;
  25.193 +  TracedCallback<Ptr<const Packet> > m_dropTrace;
  25.194 +  // Socket options (attributes)
  25.195 +  uint32_t m_rcvBufSize;
  25.196 +
  25.197 +  uint32_t m_srcPid;
  25.198 +  uint32_t m_srcGroups;
  25.199 +  uint32_t m_dstPid;
  25.200 +  uint32_t m_dstGroups;
  25.201 +  Callback<void, Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
  25.202 +};
  25.203 +
  25.204 +}//namespace ns3
  25.205 +
  25.206 +#endif /* NETLINK_SOCKET_H */
  25.207 +
  25.208 +
    26.1 --- a/model/netlink/TODO	Mon Apr 18 09:01:30 2011 +0200
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,12 +0,0 @@
    26.4 -- Notification on status change
    26.5 -- NETLINK_RTM_NEWADDR/NETLINK_RTM_DELADDR 
    26.6 -- NETLINK_RTM_SETLINK
    26.7 -   => if zebra can specify types of link
    26.8 -- NETLINK_RTM_GETLINK
    26.9 -   => Dump is implemented
   26.10 -- handle missing oif when NEW/DEL Route
   26.11 -- RT_A_SRC/RT_A_PERFSRC in NEWROUTE/DELROUTE
   26.12 -- IPv6 code (can we avoid the duplicated code btw/ v4,v6?)
   26.13 -- Multiple table from upper layer (VRF support in quagga)
   26.14 -- Doc (Doxygen)
   26.15 -- Example for netlink?
   26.16 \ No newline at end of file
    27.1 --- a/model/netlink/netlink-attribute.cc	Mon Apr 18 09:01:30 2011 +0200
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,433 +0,0 @@
    27.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    27.5 -/*
    27.6 - * Copyright (c) 2008 Liu Jian
    27.7 - *
    27.8 - * This program is free software; you can redistribute it and/or modify
    27.9 - * it under the terms of the GNU General Public License version 2 as
   27.10 - * published by the Free Software Foundation;
   27.11 - *
   27.12 - * This program is distributed in the hope that it will be useful,
   27.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   27.15 - * GNU General Public License for more details.
   27.16 - *
   27.17 - * You should have received a copy of the GNU General Public License
   27.18 - * along with this program; if not, write to the Free Software
   27.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27.20 - *
   27.21 - * Author: Liu Jian <liujatp@gmail.com>
   27.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   27.23 - */
   27.24 -
   27.25 -#include "netlink-attribute.h"
   27.26 -#include "netlink-message.h"
   27.27 -#include "netlink-message-route.h"
   27.28 -#include "ns3/address-utils.h"
   27.29 -
   27.30 -namespace ns3 {
   27.31 -
   27.32 -
   27.33 -/***********************************************************************************
   27.34 -* \ NetlinkAttributeValue
   27.35 -***********************************************************************************/
   27.36 -NetlinkAttributeValue::NetlinkAttributeValue ()
   27.37 -{
   27.38 -  m_type = UNSPEC;
   27.39 -  m_u32 = 0;
   27.40 -}
   27.41 -
   27.42 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v)
   27.43 -{
   27.44 -  NS_ASSERT (type == U8);
   27.45 -  m_type = U8;
   27.46 -  m_u8 = v;
   27.47 -}
   27.48 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v)
   27.49 -{
   27.50 -  NS_ASSERT (type == U16);
   27.51 -  m_type = U16;
   27.52 -  m_u16 = v;
   27.53 -}
   27.54 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v)
   27.55 -{
   27.56 -  NS_ASSERT (type == U32);
   27.57 -  m_type = U32;
   27.58 -  m_u32 = v;
   27.59 -}
   27.60 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v)
   27.61 -{
   27.62 -  NS_ASSERT (type == U64);
   27.63 -  m_type = U64;
   27.64 -  m_u64 = v;
   27.65 -}
   27.66 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v)
   27.67 -{
   27.68 -  NS_ASSERT (type == STRING);
   27.69 -  m_type = STRING;
   27.70 -  m_string = v;
   27.71 -}
   27.72 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, Address v)
   27.73 -{
   27.74 -  NS_ASSERT (type == ADDRESS);
   27.75 -  m_type = ADDRESS;
   27.76 -  m_address = v;
   27.77 -}
   27.78 -
   27.79 -void
   27.80 -NetlinkAttributeValue::SetType (NetlinkAttributeValueType type)
   27.81 -{
   27.82 -  m_type = type;
   27.83 -}
   27.84 -NetlinkAttributeValueType
   27.85 -NetlinkAttributeValue::GetType (void) const
   27.86 -{
   27.87 -  return m_type;
   27.88 -}
   27.89 -void
   27.90 -NetlinkAttributeValue::SetAddress (Address value)
   27.91 -{
   27.92 -  m_address = value;
   27.93 -}
   27.94 -void
   27.95 -NetlinkAttributeValue::SetString (std::string value)
   27.96 -{
   27.97 -  m_string = value;
   27.98 -}
   27.99 -void
  27.100 -NetlinkAttributeValue::SetU64 (uint64_t value)
  27.101 -{
  27.102 -  m_u64 = value;
  27.103 -}
  27.104 -void
  27.105 -NetlinkAttributeValue::SetU32 (uint32_t value)
  27.106 -{
  27.107 -  m_u32 = value;
  27.108 -}
  27.109 -void
  27.110 -NetlinkAttributeValue::SetU16 (uint16_t value)
  27.111 -{
  27.112 -  m_u16 = value;
  27.113 -}
  27.114 -void
  27.115 -NetlinkAttributeValue::SetU8 (uint8_t value)
  27.116 -{
  27.117 -  m_u8 = value;
  27.118 -}
  27.119 -Address
  27.120 -NetlinkAttributeValue::GetAddress (void) const
  27.121 -{
  27.122 -  return m_address;
  27.123 -}
  27.124 -std::string
  27.125 -NetlinkAttributeValue::GetString (void) const
  27.126 -{
  27.127 -  return m_string;
  27.128 -}
  27.129 -uint64_t
  27.130 -NetlinkAttributeValue::GetU64 (void) const
  27.131 -{
  27.132 -  return m_u64;
  27.133 -}
  27.134 -uint32_t
  27.135 -NetlinkAttributeValue::GetU32 (void) const
  27.136 -{
  27.137 -  return m_u32;
  27.138 -}
  27.139 -uint16_t
  27.140 -NetlinkAttributeValue::GetU16 (void) const
  27.141 -{
  27.142 -  return m_u16;
  27.143 -}
  27.144 -uint8_t
  27.145 -NetlinkAttributeValue::GetU8 (void) const
  27.146 -{
  27.147 -  return m_u8;
  27.148 -}
  27.149 -
  27.150 -void
  27.151 -NetlinkAttributeValue::Serialize (Buffer::Iterator& start) const
  27.152 -{
  27.153 -  uint32_t len;
  27.154 -
  27.155 -  if (m_type == U8)
  27.156 -    {
  27.157 -      start.WriteU8 (m_u8);
  27.158 -      len = 1;
  27.159 -    }
  27.160 -  else if(m_type == U16)
  27.161 -    {
  27.162 -      start.WriteU16 (m_u16);
  27.163 -      len = 2;
  27.164 -    }
  27.165 -  else if(m_type == U32)
  27.166 -    {
  27.167 -      start.WriteU32 (m_u32);
  27.168 -      len = 4;
  27.169 -    }
  27.170 -  else if(m_type == STRING)
  27.171 -    {
  27.172 -      start.Write ((const uint8_t *)m_string.c_str (), (uint32_t)m_string.size ()+1);
  27.173 -      len = (uint32_t)m_string.size () + 1;
  27.174 -    }
  27.175 -  else if(m_type == ADDRESS)
  27.176 -    {
  27.177 -      WriteTo (start, m_address);
  27.178 -      len = m_address.GetLength ();
  27.179 -    }
  27.180 -  else
  27.181 -    {
  27.182 -      len = 0;
  27.183 -    }
  27.184 -  //netlink align
  27.185 -  start.WriteU8 (0, NETLINK_MSG_ALIGN (len) - len);
  27.186 -}
  27.187 -
  27.188 -uint32_t
  27.189 -NetlinkAttributeValue::DeserializeWithType (Buffer::Iterator& start, 
  27.190 -                                            NetlinkAttributeValueType_e type, uint16_t remaining)
  27.191 -{
  27.192 -  uint32_t len =0;
  27.193 -  m_type = type;  
  27.194 -
  27.195 -  if (m_type == U8)
  27.196 -    {
  27.197 -      m_u8 = start.ReadU8 ();
  27.198 -      len = 1;
  27.199 -    }
  27.200 -  else if (m_type == U16)
  27.201 -    {
  27.202 -      m_u16 = start.ReadU16 ();
  27.203 -      len = 2;
  27.204 -    }
  27.205 -  else if (m_type == U32)
  27.206 -    {
  27.207 -      m_u32 = start.ReadU32 ();
  27.208 -      len = 4;
  27.209 -    }
  27.210 -  else if (m_type == U64)
  27.211 -    {
  27.212 -      m_u64 = start.ReadU64 ();
  27.213 -    }  
  27.214 -  else if (m_type == STRING)
  27.215 -    {
  27.216 -      char buf[512];
  27.217 -      uint32_t i = 0;
  27.218 -      do 
  27.219 -      {
  27.220 -        buf[i] = start.ReadU8 ();
  27.221 -      } while (buf[i++]);
  27.222 -      
  27.223 -      m_string = std::string (buf);
  27.224 -      len = (uint32_t)m_string.size () + 1;
  27.225 -    }
  27.226 -  else if (m_type == ADDRESS)
  27.227 -    {
  27.228 -      ReadFrom (start, m_address, remaining);
  27.229 -      len = m_address.GetLength ();
  27.230 -    }
  27.231 -  else
  27.232 -    {
  27.233 -      len = 0;
  27.234 -    }
  27.235 -
  27.236 -  //netlink align
  27.237 -  uint8_t buf[4];
  27.238 -  start.Read (buf, NETLINK_MSG_ALIGN (len) - len);
  27.239 -  
  27.240 -  return NETLINK_MSG_ALIGN (len);
  27.241 -}
  27.242 -
  27.243 -uint32_t
  27.244 -NetlinkAttributeValue::GetSerializedSize ()const
  27.245 -{
  27.246 -  return NETLINK_MSG_ALIGN (GetSize ());
  27.247 -}
  27.248 -
  27.249 -uint32_t
  27.250 -NetlinkAttributeValue::GetSize () const
  27.251 -{
  27.252 -  uint32_t len;
  27.253 -
  27.254 -  if (m_type == U8)
  27.255 -    {
  27.256 -      len = 1;
  27.257 -    }
  27.258 -  else if(m_type == U16)
  27.259 -    {
  27.260 -      len =  2;
  27.261 -    }
  27.262 -  else if(m_type == U32)
  27.263 -    {
  27.264 -      len =  4;
  27.265 -    }
  27.266 -  else if (m_type == STRING)
  27.267 -    {
  27.268 -      len =  uint32_t (m_string.size () + 1);
  27.269 -    }
  27.270 -  else if (m_type == ADDRESS)
  27.271 -    {
  27.272 -      len =  m_address.GetLength ();
  27.273 -    }
  27.274 -  else
  27.275 -    {
  27.276 -      len = 0;
  27.277 -    }
  27.278 -
  27.279 -    return len;
  27.280 -}
  27.281 -
  27.282 -void
  27.283 -NetlinkAttributeValue::Print (std::ostream &os) const
  27.284 -{
  27.285 -  os << "NetlinkAttributeValue (type= " << m_type <<", v= ";
  27.286 -  if (m_type == U8)
  27.287 -    {
  27.288 -      os << m_u8;
  27.289 -    }
  27.290 -  else if (m_type == U16)
  27.291 -    {
  27.292 -      os << m_u16;
  27.293 -    }
  27.294 -  else if (m_type == U32)
  27.295 -    {
  27.296 -      os << m_u32;
  27.297 -    }
  27.298 -  else if (m_type == U64)
  27.299 -    {
  27.300 -      os << m_u64;
  27.301 -    }  
  27.302 -  else if (m_type == STRING)
  27.303 -    {
  27.304 -      os << m_string;
  27.305 -    }
  27.306 -  else if (m_type == ADDRESS)
  27.307 -    {
  27.308 -      os << "address(" << m_address <<")";
  27.309 -    }
  27.310 -  else
  27.311 -    {
  27.312 -      os << "NULL";
  27.313 -    }
  27.314 -  os <<")";
  27.315 -}
  27.316 -
  27.317 -
  27.318 -/***********************************************************************************
  27.319 -* \ NetlinkAttribute
  27.320 -***********************************************************************************/
  27.321 -
  27.322 -NetlinkAttribute::NetlinkAttribute ()
  27.323 -  : m_len(4),
  27.324 -    m_type (0)
  27.325 -{
  27.326 -}
  27.327 -
  27.328 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload)
  27.329 -{
  27.330 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
  27.331 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  27.332 -  m_type = type;
  27.333 -}
  27.334 -
  27.335 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload)
  27.336 -{
  27.337 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
  27.338 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  27.339 -  m_type = type;
  27.340 -}
  27.341 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload)
  27.342 -{
  27.343 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
  27.344 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  27.345 -  m_type = type;;
  27.346 -}
  27.347 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload)
  27.348 -{
  27.349 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
  27.350 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  27.351 -  m_type = type;
  27.352 -}
  27.353 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload)
  27.354 -{
  27.355 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
  27.356 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  27.357 -  m_type = type;
  27.358 -}
  27.359 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload)
  27.360 -{
  27.361 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
  27.362 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  27.363 -  m_type = type;
  27.364 -}
  27.365 -
  27.366 -void
  27.367 -NetlinkAttribute::SetAttrLen (uint16_t v)
  27.368 -{
  27.369 -  m_len = v;
  27.370 -}
  27.371 -void 
  27.372 -NetlinkAttribute::SetAttrType (uint16_t v)
  27.373 -{
  27.374 -  m_type = v;
  27.375 -}
  27.376 -void
  27.377 -NetlinkAttribute::SetAttrPayload (NetlinkAttributeValue v)
  27.378 -{
  27.379 -  m_payload = v;
  27.380 -}
  27.381 -uint16_t
  27.382 -NetlinkAttribute::GetAttrLen () const
  27.383 -{
  27.384 -  return m_len;
  27.385 -}
  27.386 -uint16_t
  27.387 -NetlinkAttribute::GetAttrType () const
  27.388 -{
  27.389 -  return m_type;
  27.390 -}
  27.391 -NetlinkAttributeValue
  27.392 -NetlinkAttribute::GetAttrPayload() const
  27.393 -{
  27.394 -  return m_payload;
  27.395 -}
  27.396 -
  27.397 -void 
  27.398 -NetlinkAttribute::Print (std::ostream &os) const
  27.399 -{  
  27.400 -  os << "NetlinkAttribute "
  27.401 -     << "len: " << m_len << " "
  27.402 -     << "type: " << m_type<<" "
  27.403 -     << "payload:[";
  27.404 -  m_payload.Print(os);
  27.405 -  os<<"]";
  27.406 -}
  27.407 -
  27.408 -uint32_t 
  27.409 -NetlinkAttribute::GetSerializedSize (void) const
  27.410 -{
  27.411 -  /* this is the size of an nlattr payload. */
  27.412 -  return NETLINK_MSG_ATTR_SIZE + m_payload.GetSerializedSize ();
  27.413 -}
  27.414 -
  27.415 -void
  27.416 -NetlinkAttribute::Serialize (Buffer::Iterator& start) const
  27.417 -{
  27.418 -  start.WriteU16 (m_len);
  27.419 -  start.WriteU16 (m_type);
  27.420 -  m_payload.Serialize (start);
  27.421 -}
  27.422 -
  27.423 -uint32_t
  27.424 -NetlinkAttribute::Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[])
  27.425 -{
  27.426 -  NetlinkAttributeValueType type;
  27.427 -
  27.428 -  m_len = start.ReadU16 ();
  27.429 -  m_type = start.ReadU16 ();
  27.430 -  type = vtypes[m_type];
  27.431 -  m_payload.DeserializeWithType (start, type, m_len - 4);
  27.432 -
  27.433 -  return GetSerializedSize ();
  27.434 -}
  27.435 -
  27.436 -}; // namespace ns3
    28.1 --- a/model/netlink/netlink-attribute.h	Mon Apr 18 09:01:30 2011 +0200
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,124 +0,0 @@
    28.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    28.5 -/*
    28.6 - * Copyright (c) 2008 Liu Jian
    28.7 - *
    28.8 - * This program is free software; you can redistribute it and/or modify
    28.9 - * it under the terms of the GNU General Public License version 2 as
   28.10 - * published by the Free Software Foundation;
   28.11 - *
   28.12 - * This program is distributed in the hope that it will be useful,
   28.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   28.15 - * GNU General Public License for more details.
   28.16 - *
   28.17 - * You should have received a copy of the GNU General Public License
   28.18 - * along with this program; if not, write to the Free Software
   28.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.20 - *
   28.21 - * Author: Liu Jian <liujatp@gmail.com>
   28.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   28.23 - */
   28.24 -
   28.25 -#ifndef NETLINK_ATTRIBUTE_H
   28.26 -#define NETLINK_ATTRIBUTE_H
   28.27 -
   28.28 -
   28.29 -#include <stdint.h>
   28.30 -#include <string>
   28.31 -#include <ostream>
   28.32 -#include "ns3/address.h"
   28.33 -#include "ns3/buffer.h"
   28.34 -
   28.35 -namespace ns3 {
   28.36 -
   28.37 -/**
   28.38 -* \brief The Netlink Attribute
   28.39 -*/
   28.40 -
   28.41 -typedef enum NetlinkAttributeValueType_e {
   28.42 -  UNSPEC, // invalid initial value.
   28.43 -  U8,
   28.44 -  U16,
   28.45 -  U32,
   28.46 -  U64,
   28.47 -  STRING,
   28.48 -  ADDRESS,
   28.49 -}NetlinkAttributeValueType;
   28.50 -
   28.51 -class NetlinkAttributeValue
   28.52 -{
   28.53 -public:
   28.54 -  NetlinkAttributeValue ();
   28.55 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v);
   28.56 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v);
   28.57 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v);
   28.58 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v);
   28.59 -  NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v);
   28.60 -  NetlinkAttributeValue (NetlinkAttributeValueType type, Address v);
   28.61 -  
   28.62 -  void Serialize (Buffer::Iterator& start) const;
   28.63 -  uint32_t DeserializeWithType (Buffer::Iterator& start, NetlinkAttributeValueType type, uint16_t remaining);
   28.64 -  uint32_t GetSerializedSize (void) const;
   28.65 -  uint32_t GetSize (void) const;
   28.66 -  void Print (std::ostream &os) const;
   28.67 -
   28.68 -  void SetType (NetlinkAttributeValueType type);
   28.69 -  NetlinkAttributeValueType GetType (void) const;
   28.70 -  void SetAddress (Address value);
   28.71 -  void SetString (std::string value);
   28.72 -  void SetU64 (uint64_t value);
   28.73 -  void SetU32 (uint32_t value);
   28.74 -  void SetU16 (uint16_t value);
   28.75 -  void SetU8 (uint8_t value);
   28.76 -  Address GetAddress (void) const;
   28.77 -  std::string GetString (void) const;
   28.78 -  uint64_t GetU64 (void) const;
   28.79 -  uint32_t GetU32 (void) const;
   28.80 -  uint16_t GetU16 (void) const;
   28.81 -  uint8_t GetU8 (void) const;
   28.82 -
   28.83 -private:
   28.84 -  NetlinkAttributeValueType m_type;
   28.85 -  uint64_t m_u64;
   28.86 -  uint32_t m_u32;
   28.87 -  uint16_t m_u16;
   28.88 -  uint8_t m_u8;
   28.89 -  std::string m_string;
   28.90 -  Address m_address;
   28.91 -};
   28.92 -
   28.93 -struct NetlinkAttribute
   28.94 -{
   28.95 -public:
   28.96 -  NetlinkAttribute ();
   28.97 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload);
   28.98 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload);
   28.99 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload);
  28.100 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload);
  28.101 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload);
  28.102 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload);
  28.103 -
  28.104 -  //static TypeId GetTypeId (void);
  28.105 -  //virtual TypeId GetInstanceTypeId (void) const;
  28.106 -  void Print (std::ostream &os) const;
  28.107 -  uint32_t GetSerializedSize (void) const;
  28.108 -  void Serialize (Buffer::Iterator& start) const;
  28.109 -  uint32_t Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[]);
  28.110 -
  28.111 -  void SetAttrLen (uint16_t v);
  28.112 -  void SetAttrType (uint16_t v);
  28.113 -  void SetAttrPayload (NetlinkAttributeValue v);
  28.114 -  uint16_t GetAttrLen () const;
  28.115 -  uint16_t GetAttrType () const;
  28.116 -  NetlinkAttributeValue GetAttrPayload () const;
  28.117 -
  28.118 -private:
  28.119 -  static const int NETLINK_MSG_ATTR_SIZE = 4; /* size of the nlattr field*/
  28.120 -  uint16_t m_len;
  28.121 -  uint16_t m_type; 
  28.122 -  NetlinkAttributeValue m_payload;
  28.123 -};
  28.124 -
  28.125 -}; // namespace ns3
  28.126 -
  28.127 -#endif /* NETLINK_ATTRIBUTE_H */
    29.1 --- a/model/netlink/netlink-message-route.cc	Mon Apr 18 09:01:30 2011 +0200
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,647 +0,0 @@
    29.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    29.5 -/*
    29.6 - * Copyright (c) 2008 Liu Jian
    29.7 - *
    29.8 - * This program is free software; you can redistribute it and/or modify
    29.9 - * it under the terms of the GNU General Public License version 2 as
   29.10 - * published by the Free Software Foundation;
   29.11 - *
   29.12 - * This program is distributed in the hope that it will be useful,
   29.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   29.15 - * GNU General Public License for more details.
   29.16 - *
   29.17 - * You should have received a copy of the GNU General Public License
   29.18 - * along with this program; if not, write to the Free Software
   29.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   29.20 - *
   29.21 - * Author: Liu Jian <liujatp@gmail.com>
   29.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   29.23 - */
   29.24 -
   29.25 -#include "netlink-message-route.h"
   29.26 -#include "netlink-message.h"
   29.27 -
   29.28 -namespace ns3 {
   29.29 -
   29.30 -/***********************************************************************************
   29.31 -* \ NetlinkPayload
   29.32 -***********************************************************************************/
   29.33 -TypeId 
   29.34 -NetlinkPayload::GetTypeId (void)
   29.35 -{
   29.36 -  static TypeId tid = TypeId ("ns3::NetlinkPayload")
   29.37 -    .SetParent<ObjectBase> ()
   29.38 -    ;
   29.39 -  return tid;
   29.40 -}
   29.41 -
   29.42 -
   29.43 -/***********************************************************************************
   29.44 -* \ GeneralMessage
   29.45 -***********************************************************************************/
   29.46 -
   29.47 -NS_OBJECT_ENSURE_REGISTERED (GeneralMessage);
   29.48 -NS_OBJECT_ENSURE_REGISTERED (InterfaceInfoMessage);
   29.49 -NS_OBJECT_ENSURE_REGISTERED (InterfaceAddressMessage);
   29.50 -NS_OBJECT_ENSURE_REGISTERED (RouteMessage);
   29.51 -
   29.52 -GeneralMessage::GeneralMessage ()
   29.53 -  : m_family(0)
   29.54 -{}
   29.55 -GeneralMessage::~GeneralMessage ()
   29.56 -{}
   29.57 -
   29.58 -void
   29.59 -GeneralMessage::SetFamily (uint8_t v)
   29.60 -{
   29.61 -  m_family = v;
   29.62 -}
   29.63 -uint8_t
   29.64 -GeneralMessage::GetFamily (void) const
   29.65 -{
   29.66 -  return m_family;
   29.67 -}
   29.68 -
   29.69 -TypeId 
   29.70 -GeneralMessage::GetTypeId (void)
   29.71 -{
   29.72 -  static TypeId tid = TypeId ("ns3::GeneralMessage")
   29.73 -    .SetParent<NetlinkPayload> ()
   29.74 -    .AddConstructor<GeneralMessage> ()
   29.75 -    ;
   29.76 -  return tid;
   29.77 -}
   29.78 -
   29.79 -TypeId 
   29.80 -GeneralMessage::GetInstanceTypeId (void) const
   29.81 -{
   29.82 -  return GetTypeId ();
   29.83 -}
   29.84 -void 
   29.85 -GeneralMessage::Print (std::ostream &os) const
   29.86 -{
   29.87 -  os << " ----GeneralMessage ("
   29.88 -     << "family: " << (uint32_t)m_family << ")"; 
   29.89 -}
   29.90 -
   29.91 -uint32_t 
   29.92 -GeneralMessage::GetSerializedSize (void) const
   29.93 -{
   29.94 -  /* this is the size of an nlmsghdr payload. */
   29.95 -  return NETLINK_MSG_ALIGN (NETLINK_GENMSG_SIZE);
   29.96 -}
   29.97 -
   29.98 -
   29.99 -void
  29.100 -GeneralMessage::Serialize (Buffer::Iterator& start) const
  29.101 -{
  29.102 -  start.WriteU8 (m_family);
  29.103 -  start.WriteU8 (0, 3);
  29.104 -}
  29.105 -
  29.106 -uint32_t
  29.107 -GeneralMessage::Deserialize (Buffer::Iterator& start)
  29.108 -{
  29.109 -  uint8_t buf[3];
  29.110 -  m_family = start.ReadU8 ();
  29.111 -  start.Read (buf, 3);
  29.112 -  return GetSerializedSize ();
  29.113 -}
  29.114 -uint32_t
  29.115 -GeneralMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  29.116 -{
  29.117 -  uint8_t buf[3];
  29.118 -  m_family = start.ReadU8 ();
  29.119 -  start.Read (buf, 3);
  29.120 -  return GetSerializedSize ();
  29.121 -}
  29.122 -
  29.123 -
  29.124 -uint32_t
  29.125 -GeneralMessage::GetNNetlinkAttribute (void)const
  29.126 -{
  29.127 -  return m_attributes.size ();
  29.128 -}
  29.129 -NetlinkAttribute
  29.130 -GeneralMessage::GetNetlinkAttribute (uint32_t index)const
  29.131 -{
  29.132 -  NS_ASSERT(index < GetNNetlinkAttribute ());
  29.133 -  return m_attributes[index];
  29.134 -}
  29.135 -
  29.136 -uint32_t
  29.137 -GeneralMessage::GetAttributeSerializedSize (void) const
  29.138 -{
  29.139 -  uint32_t size = 0;
  29.140 -
  29.141 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  29.142 -    {
  29.143 -      size += m_attributes[i].GetSerializedSize ();
  29.144 -    }
  29.145 -  return size;
  29.146 -}
  29.147 -bool
  29.148 -GeneralMessage::GetAttributeByType (NetlinkAttribute& attr, uint16_t type)
  29.149 -{
  29.150 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  29.151 -    {
  29.152 -      if (type == m_attributes[i].GetAttrType ())
  29.153 -        {
  29.154 -          attr = m_attributes[i];
  29.155 -          return true;
  29.156 -        }
  29.157 -    }
  29.158 -  return false;  
  29.159 -}
  29.160 -void
  29.161 -GeneralMessage::AppendAttribute (NetlinkAttribute v)
  29.162 -{
  29.163 -  m_attributes.push_back (v);
  29.164 -}
  29.165 -
  29.166 -void
  29.167 -GeneralMessage::SerializeAttribute (Buffer::Iterator& start) const
  29.168 -{
  29.169 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  29.170 -    {
  29.171 -      m_attributes[i].Serialize (start);
  29.172 -    }
  29.173 -}
  29.174 -
  29.175 -void
  29.176 -GeneralMessage::PrintAttribute (std::ostream &os) const
  29.177 -{
  29.178 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  29.179 -    {
  29.180 -      os << " ----Attribute (" << i << "):";
  29.181 -      m_attributes[i].Print(os);
  29.182 -    }
  29.183 -}
  29.184 -
  29.185 -/***********************************************************************************
  29.186 -* \ InterfaceInfoMessage
  29.187 -***********************************************************************************/
  29.188 -InterfaceInfoMessage::InterfaceInfoMessage ()
  29.189 -  : m_reserved (0),
  29.190 -    m_deviceType (0),
  29.191 -    m_interfaceIndex(0),
  29.192 -    m_deviceFlags (0),
  29.193 -    m_changeMask (0)
  29.194 -{
  29.195 -  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  29.196 -  m_attributeTypes[IFL_A_UNSPEC] = UNSPEC;
  29.197 -  m_attributeTypes[IFL_A_ADDRESS] = ADDRESS;
  29.198 -  m_attributeTypes[IFL_A_BROADCAST] = ADDRESS;
  29.199 -  m_attributeTypes[IFL_A_IFNAME] = STRING;
  29.200 -  m_attributeTypes[IFL_A_MTU] = U32;
  29.201 -  m_attributeTypes[IFL_A_LINK] = U32;
  29.202 -  m_attributeTypes[IFL_A_QDISC] = U8;
  29.203 -  m_attributeTypes[IFL_A_STATS] = UNSPEC;
  29.204 -  m_attributeTypes[IFL_A_COST] = UNSPEC;
  29.205 -}
  29.206 -InterfaceInfoMessage::~InterfaceInfoMessage ()
  29.207 -{}
  29.208 -void
  29.209 -InterfaceInfoMessage::SetDeviceType (uint16_t type)
  29.210 -{
  29.211 -  m_deviceType = type;
  29.212 -}
  29.213 -void
  29.214 -InterfaceInfoMessage::SetInterfaceIndex (int32_t index)
  29.215 -{
  29.216 -  m_interfaceIndex = index;
  29.217 -}
  29.218 -void
  29.219 -InterfaceInfoMessage::SetDeviceFlags (uint32_t flags)
  29.220 -{
  29.221 -  m_deviceFlags = flags;
  29.222 -}
  29.223 -void
  29.224 -InterfaceInfoMessage::SetChangeMask (uint32_t mask)
  29.225 -{
  29.226 -  m_changeMask = mask;
  29.227 -}
  29.228 -uint16_t
  29.229 -InterfaceInfoMessage::GetDeviceType (void) const
  29.230 -{
  29.231 -  return m_deviceType;
  29.232 -}
  29.233 -int32_t
  29.234 -InterfaceInfoMessage::GetInterfaceIndex (void) const
  29.235 -{
  29.236 -  return m_interfaceIndex;
  29.237 -}
  29.238 -uint32_t
  29.239 -InterfaceInfoMessage::GetDeviceFlags (void) const
  29.240 -{
  29.241 -  return m_deviceFlags;
  29.242 -}
  29.243 -uint32_t
  29.244 -InterfaceInfoMessage::GetChangeMask (void) const
  29.245 -{
  29.246 -  return m_changeMask;
  29.247 -}
  29.248 -TypeId 
  29.249 -InterfaceInfoMessage::GetTypeId (void)
  29.250 -{
  29.251 -  static TypeId tid = TypeId ("ns3::InterfaceInfoMessage")
  29.252 -    .SetParent<GeneralMessage> ()
  29.253 -    .AddConstructor<InterfaceInfoMessage> ()
  29.254 -    ;
  29.255 -  return tid;
  29.256 -}
  29.257 -TypeId 
  29.258 -InterfaceInfoMessage::GetInstanceTypeId (void) const
  29.259 -{
  29.260 -  return GetTypeId ();
  29.261 -}
  29.262 -void 
  29.263 -InterfaceInfoMessage::Print (std::ostream &os) const
  29.264 -{  
  29.265 -  os << " ----InterfaceInfoMessage ("
  29.266 -     << "deviceType: " << m_deviceType << " "
  29.267 -     << "interfaceIndex: " << m_interfaceIndex << " "
  29.268 -     << "deviceFlags: " << m_deviceFlags << " "
  29.269 -     << "changeMask: " << m_changeMask << ")" ;
  29.270 -  PrintAttribute (os);
  29.271 -}
  29.272 -uint32_t 
  29.273 -InterfaceInfoMessage::GetSerializedSize (void) const
  29.274 -{
  29.275 -  return NETLINK_INTERFACE_SIZE + GetAttributeSerializedSize ();
  29.276 -}
  29.277 -
  29.278 -void
  29.279 -InterfaceInfoMessage::Serialize (Buffer::Iterator& start) const
  29.280 -{
  29.281 -  start.WriteU8 (m_family);
  29.282 -  start.WriteU8 (m_reserved);
  29.283 -  start.WriteU16 (m_deviceType);
  29.284 -  start.WriteU32 (m_interfaceIndex);
  29.285 -  start.WriteU32 (m_deviceFlags);
  29.286 -  start.WriteU32 (m_changeMask);
  29.287 -
  29.288 -  SerializeAttribute (start);
  29.289 -}
  29.290 -uint32_t
  29.291 -InterfaceInfoMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  29.292 -{
  29.293 -  m_family = start.ReadU8 ();
  29.294 -  m_reserved = start.ReadU8 ();
  29.295 -  m_deviceType = start.ReadU16 ();
  29.296 -  m_interfaceIndex = start.ReadU32 ();
  29.297 -  m_deviceFlags = start.ReadU32 ();
  29.298 -  m_changeMask = start.ReadU32 ();
  29.299 -
  29.300 -  len -= NETLINK_INTERFACE_SIZE;
  29.301 -
  29.302 -  while (len)
  29.303 -    {
  29.304 -      NetlinkAttribute attr;
  29.305 -
  29.306 -      len -= attr.Deserialize (start, m_attributeTypes);
  29.307 -      m_attributes.push_back (attr);
  29.308 -    }
  29.309 -
  29.310 -  return GetSerializedSize ();
  29.311 -}
  29.312 -
  29.313 -
  29.314 -
  29.315 -/***********************************************************************************
  29.316 -* \InterfaceAddressMessage
  29.317 -***********************************************************************************/
  29.318 -InterfaceAddressMessage::InterfaceAddressMessage ()
  29.319 -  : m_length (0),
  29.320 -    m_flags (0),
  29.321 -    m_scope (0),
  29.322 -    m_index(0)
  29.323 -{
  29.324 -  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  29.325 -  m_attributeTypes[IF_A_UNSPEC] = UNSPEC;
  29.326 -  m_attributeTypes[IF_A_ADDRESS] = ADDRESS;
  29.327 -  m_attributeTypes[IF_A_LOCAL] = ADDRESS;
  29.328 -  m_attributeTypes[IF_A_LABEL] = STRING;
  29.329 -  m_attributeTypes[IF_A_BROADCAST] = ADDRESS;
  29.330 -  m_attributeTypes[IF_A_ANYCAST] = ADDRESS;
  29.331 -  m_attributeTypes[IF_A_CACHEINFO] = UNSPEC;
  29.332 -  m_attributeTypes[IF_A_MULTICAST] = ADDRESS;
  29.333 -}
  29.334 -InterfaceAddressMessage::~InterfaceAddressMessage ()
  29.335 -{
  29.336 -}
  29.337 -void
  29.338 -InterfaceAddressMessage::SetFamily (uint8_t family)
  29.339 -{
  29.340 -  m_family = family;
  29.341 -}
  29.342 -void
  29.343 -InterfaceAddressMessage::SetLength (uint8_t length)
  29.344 -{
  29.345 -  m_length = length;
  29.346 -}
  29.347 -void
  29.348 -InterfaceAddressMessage::SetFlags (uint8_t flags)
  29.349 -{
  29.350 -  m_flags = flags;
  29.351 -}
  29.352 -void
  29.353 -InterfaceAddressMessage::SetScope (uint8_t scope)
  29.354 -{
  29.355 -  m_scope = scope;
  29.356 -}
  29.357 -void
  29.358 -InterfaceAddressMessage::SetInterfaceIndex (int32_t index)
  29.359 -{
  29.360 -  m_index = index;
  29.361 -}
  29.362 -
  29.363 -uint8_t
  29.364 -InterfaceAddressMessage::GetFamily (void) const
  29.365 -{
  29.366 -  return m_family;
  29.367 -}
  29.368 -uint8_t
  29.369 -InterfaceAddressMessage::GetLength (void) const
  29.370 -{
  29.371 -  return m_length;
  29.372 -}
  29.373 -uint8_t
  29.374 -InterfaceAddressMessage::GetFlags (void) const
  29.375 -{
  29.376 -  return m_flags;
  29.377 -}
  29.378 -uint8_t
  29.379 -InterfaceAddressMessage::GetScope (void) const
  29.380 -{
  29.381 -  return m_scope;
  29.382 -}
  29.383 -int32_t
  29.384 -InterfaceAddressMessage::GetInterfaceIndex (void) const
  29.385 -{
  29.386 -  return m_index;
  29.387 -}
  29.388 -
  29.389 -TypeId 
  29.390 -InterfaceAddressMessage::GetTypeId (void)
  29.391 -{
  29.392 -  static TypeId tid = TypeId ("ns3::InterfaceAddressMessage")
  29.393 -    .SetParent<GeneralMessage> ()
  29.394 -    .AddConstructor<InterfaceAddressMessage> ()
  29.395 -    ;
  29.396 -  return tid;
  29.397 -}
  29.398 -TypeId 
  29.399 -InterfaceAddressMessage::GetInstanceTypeId (void) const
  29.400 -{
  29.401 -  return GetTypeId ();
  29.402 -}
  29.403 -void 
  29.404 -InterfaceAddressMessage::Print (std::ostream &os) const
  29.405 -{  
  29.406 -  os << " ----InterfaceAddressMessage ("
  29.407 -     << "family: " << (uint32_t)m_family << " "
  29.408 -     << "length: " << (uint32_t)m_length << " "
  29.409 -     << "flags: " << (uint32_t)m_flags << " "
  29.410 -     << "scope: " << (uint32_t)m_scope << " "
  29.411 -     << "index: " << m_index << ")";
  29.412 -  PrintAttribute (os);
  29.413 -}
  29.414 -uint32_t 
  29.415 -InterfaceAddressMessage::GetSerializedSize (void) const
  29.416 -{
  29.417 -  return NETLINK_ADDRESS_SIZE + GetAttributeSerializedSize ();
  29.418 -}
  29.419 -
  29.420 -void
  29.421 -InterfaceAddressMessage::Serialize (Buffer::Iterator& start) const
  29.422 -{
  29.423 -  start.WriteU8 (m_family);
  29.424 -  start.WriteU8 (m_length);
  29.425 -  start.WriteU8 (m_flags);
  29.426 -  start.WriteU8 (m_scope);
  29.427 -  start.WriteU32 (m_index);
  29.428 -
  29.429 -  SerializeAttribute(start);
  29.430 -}
  29.431 -
  29.432 -uint32_t
  29.433 -InterfaceAddressMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  29.434 -{
  29.435 -  m_family = start.ReadU8 ();
  29.436 -  m_length = start.ReadU8 ();
  29.437 -  m_flags = start.ReadU8 ();
  29.438 -  m_scope = start.ReadU8 ();
  29.439 -  m_index = start.ReadU32 ();
  29.440 -
  29.441 -  len -= NETLINK_ADDRESS_SIZE;
  29.442 -
  29.443 -  while (len)
  29.444 -    {
  29.445 -      NetlinkAttribute attr;
  29.446 -
  29.447 -      len -= attr.Deserialize (start, m_attributeTypes);
  29.448 -      m_attributes.push_back (attr);
  29.449 -    }
  29.450 -
  29.451 -  return GetSerializedSize ();
  29.452 -}
  29.453 -
  29.454 -
  29.455 -
  29.456 -/***********************************************************************************
  29.457 -* \ RouteMessage
  29.458 -***********************************************************************************/
  29.459 -RouteMessage::RouteMessage ()
  29.460 -  : m_dstLen (0),
  29.461 -    m_srcLen (0),
  29.462 -    m_tos (0),
  29.463 -    m_tableId (0),
  29.464 -    m_protocol(0),
  29.465 -    m_scope (0),
  29.466 -    m_type (0),
  29.467 -    m_flags (0)
  29.468 -{
  29.469 -  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  29.470 -  m_attributeTypes[RT_A_UNSPEC] = UNSPEC;
  29.471 -  m_attributeTypes[RT_A_DST] = ADDRESS;
  29.472 -  m_attributeTypes[RT_A_SRC] = ADDRESS;
  29.473 -  m_attributeTypes[RT_A_IIF] = U32;
  29.474 -  m_attributeTypes[RT_A_OIF] = U32;
  29.475 -  m_attributeTypes[RT_A_GATEWAY] = ADDRESS;
  29.476 -  m_attributeTypes[RT_A_PRIORITY] = U8;
  29.477 -  m_attributeTypes[RT_A_PREFSRC] = ADDRESS;
  29.478 -  m_attributeTypes[RT_A_METRICS] = UNSPEC;
  29.479 -  //others default value UNSPEC
  29.480 -}
  29.481 -RouteMessage::~RouteMessage ()
  29.482 -{}
  29.483 -
  29.484 -void
  29.485 -RouteMessage::SetFamily (uint8_t v)
  29.486 -{
  29.487 -  m_family = v;
  29.488 -}
  29.489 -void
  29.490 -RouteMessage::SetDstLength (uint8_t v)
  29.491 -{
  29.492 -  m_dstLen = v;
  29.493 -}
  29.494 -void
  29.495 -RouteMessage::SetSrcLength (uint8_t v)
  29.496 -{
  29.497 -  m_srcLen = v;
  29.498 -}
  29.499 -void
  29.500 -RouteMessage::SetTos (uint8_t v)
  29.501 -{
  29.502 -  m_tos = v;
  29.503 -}
  29.504 -void
  29.505 -RouteMessage::SetTableId (uint8_t v)
  29.506 -{
  29.507 -  m_tableId = v;
  29.508 -}
  29.509 -void
  29.510 -RouteMessage::SetProtocol (uint8_t v)
  29.511 -{
  29.512 -  m_protocol = v;
  29.513 -}
  29.514 -void
  29.515 -RouteMessage::SetScope (uint8_t v)
  29.516 -{
  29.517 -  m_scope = v;
  29.518 -}
  29.519 -void
  29.520 -RouteMessage::SetType (uint8_t v)
  29.521 -{
  29.522 -  m_type = v;
  29.523 -}
  29.524 -void
  29.525 -RouteMessage::SetFlags (uint32_t v)
  29.526 -{
  29.527 -  m_flags = v;
  29.528 -}
  29.529 -uint8_t
  29.530 -RouteMessage::GetFamily (void) const
  29.531 -{
  29.532 -  return m_family;
  29.533 -}
  29.534 -uint8_t
  29.535 -RouteMessage::GetDstLength (void) const
  29.536 -{
  29.537 -  return m_dstLen;
  29.538 -}
  29.539 -uint8_t
  29.540 -RouteMessage::GetSrcLength (void) const
  29.541 -{
  29.542 -  return m_srcLen;
  29.543 -}
  29.544 -uint8_t
  29.545 -RouteMessage::GetTos (void) const
  29.546 -{
  29.547 -  return m_tos;
  29.548 -}
  29.549 -uint8_t
  29.550 -RouteMessage::GetTableId (void) const
  29.551 -{
  29.552 -  return m_tableId;
  29.553 -}
  29.554 -uint8_t
  29.555 -RouteMessage::GetProtocol (void) const
  29.556 -{
  29.557 -  return m_protocol;
  29.558 -}
  29.559 -uint8_t
  29.560 -RouteMessage::GetType (void) const
  29.561 -{
  29.562 -  return m_type;
  29.563 -}
  29.564 -uint8_t
  29.565 -RouteMessage::GetScope (void) const
  29.566 -{
  29.567 -  return m_scope;
  29.568 -}
  29.569 -uint32_t
  29.570 -RouteMessage::GetFlags (void) const
  29.571 -{
  29.572 -  return m_flags;
  29.573 -}
  29.574 -
  29.575 -TypeId 
  29.576 -RouteMessage::GetTypeId (void)
  29.577 -{
  29.578 -  static TypeId tid = TypeId ("ns3::RouteMessage")
  29.579 -    .SetParent<GeneralMessage> ()
  29.580 -    .AddConstructor<RouteMessage> ()
  29.581 -    ;
  29.582 -  return tid;
  29.583 -}
  29.584 -TypeId 
  29.585 -RouteMessage::GetInstanceTypeId (void) const
  29.586 -{
  29.587 -  return GetTypeId ();
  29.588 -}
  29.589 -void 
  29.590 -RouteMessage::Print (std::ostream &os) const
  29.591 -{  
  29.592 -  os << " ----RouteMessage ("
  29.593 -     << "family: " << (uint32_t)m_family << " "
  29.594 -     << "dstLen: " << (uint32_t)m_dstLen << " "
  29.595 -     << "srcLen: " << (uint32_t)m_srcLen << " "
  29.596 -     << "tos: " << (uint32_t)m_tos << " "
  29.597 -     << "tableId: " << (uint32_t)m_tableId << " "
  29.598 -     << "protocol: " << (uint32_t)m_protocol << " "
  29.599 -     << "scope: " << (uint32_t)m_scope << " "
  29.600 -     << "type: " << (uint32_t)m_type << " "
  29.601 -     << "flags: " << m_flags<< ")" ;
  29.602 -  PrintAttribute (os);
  29.603 -}
  29.604 -uint32_t 
  29.605 -RouteMessage::GetSerializedSize (void) const
  29.606 -{
  29.607 -  return NETLINK_ROUTE_SIZE + GetAttributeSerializedSize ();
  29.608 -}
  29.609 -
  29.610 -void
  29.611 -RouteMessage::Serialize (Buffer::Iterator& start) const
  29.612 -{
  29.613 -  start.WriteU8 (m_family);
  29.614 -  start.WriteU8 (m_dstLen);
  29.615 -  start.WriteU8 (m_srcLen);
  29.616 -  start.WriteU8 (m_tos);
  29.617 -  start.WriteU8 (m_tableId);
  29.618 -  start.WriteU8 (m_protocol);
  29.619 -  start.WriteU8 (m_scope);
  29.620 -  start.WriteU8 (m_type);
  29.621 -  start.WriteU32 (m_flags);
  29.622 -
  29.623 -  SerializeAttribute (start);
  29.624 -}
  29.625 -uint32_t
  29.626 -RouteMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  29.627 -{
  29.628 -  m_family = start.ReadU8 ();
  29.629 -  m_dstLen = start.ReadU8 ();
  29.630 -  m_srcLen = start.ReadU8 ();
  29.631 -  m_tos = start.ReadU8 ();
  29.632 -  m_tableId = start.ReadU8 ();
  29.633 -  m_protocol = start.ReadU8 ();
  29.634 -  m_scope = start.ReadU8 ();
  29.635 -  m_type = start.ReadU8 ();
  29.636 -  m_flags = start.ReadU32 ();
  29.637 -
  29.638 -  len -= NETLINK_ROUTE_SIZE;
  29.639 -
  29.640 -  while (len)
  29.641 -    {
  29.642 -      NetlinkAttribute attr;
  29.643 -
  29.644 -      len -= attr.Deserialize (start, m_attributeTypes);
  29.645 -      m_attributes.push_back (attr);
  29.646 -    }
  29.647 -
  29.648 -  return GetSerializedSize ();
  29.649 -}
  29.650 -}; // namespace ns3
    30.1 --- a/model/netlink/netlink-message-route.h	Mon Apr 18 09:01:30 2011 +0200
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,388 +0,0 @@
    30.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    30.5 -/*
    30.6 - * Copyright (c) 2008 Liu Jian
    30.7 - *
    30.8 - * This program is free software; you can redistribute it and/or modify
    30.9 - * it under the terms of the GNU General Public License version 2 as
   30.10 - * published by the Free Software Foundation;
   30.11 - *
   30.12 - * This program is distributed in the hope that it will be useful,
   30.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   30.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   30.15 - * GNU General Public License for more details.
   30.16 - *
   30.17 - * You should have received a copy of the GNU General Public License
   30.18 - * along with this program; if not, write to the Free Software
   30.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   30.20 - *
   30.21 - * Author: Liu Jian <liujatp@gmail.com>
   30.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   30.23 - */
   30.24 -
   30.25 -#ifndef NETLINK_MESSAGE_ROUTE_H
   30.26 -#define NETLINK_MESSAGE_ROUTE_H
   30.27 -
   30.28 -#include "ns3/object-base.h"
   30.29 -#include "ns3/address.h"
   30.30 -#include "netlink-attribute.h"
   30.31 -#include <string>
   30.32 -
   30.33 -namespace ns3 {
   30.34 -
   30.35 -/*
   30.36 -* this file define some netlink message of NETLINK_ROUTE protocol,
   30.37 -* there are mainly three types:interface address, interface info, route entry
   30.38 -* just implemented them for quagga porting.
   30.39 -*/
   30.40 -  
   30.41 -
   30.42 -
   30.43 -/**
   30.44 -* \Types of messages,here we only define the route message types quagga used
   30.45 -*/
   30.46 -enum NetlinkRtmType_e {
   30.47 -  NETLINK_RTM_BASE = 16,
   30.48 -
   30.49 -  NETLINK_RTM_NEWLINK = 16,
   30.50 -  NETLINK_RTM_DELLINK,
   30.51 -  NETLINK_RTM_GETLINK,
   30.52 -  NETLINK_RTM_SETLINK,
   30.53 -
   30.54 -  NETLINK_RTM_NEWADDR = 20,
   30.55 -  NETLINK_RTM_DELADDR,
   30.56 -  NETLINK_RTM_GETADDR,
   30.57 -
   30.58 -  NETLINK_RTM_NEWROUTE = 24,
   30.59 -  NETLINK_RTM_DELROUTE,
   30.60 -  NETLINK_RTM_GETROUTE,
   30.61 -
   30.62 -  NETLINK_RTM_MAX,
   30.63 -};  
   30.64 -
   30.65 -/**
   30.66 -* \Types of netlink groups,here we only define types quagga used
   30.67 -*/
   30.68 -enum NetlinkRtmGroup_e {
   30.69 -  NETLINK_RTM_GRP_LINK = 1,
   30.70 -  NETLINK_RTM_GRP_IPV4_IFADDR = 0x10,
   30.71 -  NETLINK_RTM_GRP_IPV4_ROUTE = 0x40,
   30.72 -  RTMGRP_IPV6_IFADDR = 0x100,
   30.73 -  RTMGRP_IPV6_ROUTE = 0x400,
   30.74 -};
   30.75 -
   30.76 -class NetlinkPayload :public ObjectBase
   30.77 -{
   30.78 -public:
   30.79 -  static TypeId GetTypeId (void);
   30.80 -  virtual TypeId GetInstanceTypeId (void) const = 0;
   30.81 -  virtual void Serialize (Buffer::Iterator& start) const = 0;
   30.82 -  virtual void Print (std::ostream &os) const = 0;
   30.83 -  virtual uint32_t GetSerializedSize (void) const = 0;
   30.84 -};
   30.85 -
   30.86 -/***
   30.87 - General form of address family dependent message.
   30.88 -
   30.89 -  struct rtgenmsg
   30.90 -  {
   30.91 -    unsigned char		rtgen_family;
   30.92 -  };
   30.93 -**/
   30.94 -
   30.95 -class GeneralMessage : public NetlinkPayload
   30.96 -{
   30.97 -public:
   30.98 -  GeneralMessage ();
   30.99 -  virtual ~GeneralMessage ();
  30.100 -
  30.101 -  static TypeId GetTypeId (void);
  30.102 -  virtual TypeId GetInstanceTypeId (void) const;
  30.103 -  virtual void Serialize (Buffer::Iterator& start) const;
  30.104 -  virtual uint32_t Deserialize (Buffer::Iterator& start);
  30.105 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  30.106 -  virtual void Print (std::ostream &os) const;
  30.107 -  virtual uint32_t GetSerializedSize (void) const;
  30.108 -
  30.109 -  
  30.110 -  virtual uint32_t GetNNetlinkAttribute (void)const;
  30.111 -  virtual NetlinkAttribute GetNetlinkAttribute (uint32_t index)const;
  30.112 -  virtual void AppendAttribute (NetlinkAttribute v);
  30.113 -  virtual void SerializeAttribute (Buffer::Iterator& start) const;
  30.114 -  virtual void PrintAttribute (std::ostream &os) const;
  30.115 -  virtual uint32_t GetAttributeSerializedSize (void) const;
  30.116 -  virtual bool GetAttributeByType (NetlinkAttribute& attr, uint16_t type);
  30.117 -
  30.118 -
  30.119 -  void SetFamily (uint8_t v);
  30.120 -  uint8_t GetFamily (void) const;
  30.121 -
  30.122 -private:
  30.123 -  static const int NETLINK_GENMSG_SIZE = 1; /* size of the struct rtgenmsg */  
  30.124 -protected:
  30.125 -  uint8_t m_family;   //always set to AF_UNSPEC
  30.126 -  //attribute can exist or not
  30.127 -  std::vector<NetlinkAttribute> m_attributes;
  30.128 -};
  30.129 -
  30.130 -
  30.131 -
  30.132 -/**
  30.133 -* \brief Link layer specific messages
  30.134 -*
  30.135 -* struct ifinfomsg
  30.136 -* passes link level specific information, not dependent
  30.137 -* on network protocol.
  30.138 -*
  30.139 -  struct ifinfomsg
  30.140 -  {
  30.141 -    unsigned char	ifi_family;
  30.142 -    unsigned char	__ifi_pad;
  30.143 -    unsigned short	ifi_type;
  30.144 -    int		ifi_index;	
  30.145 -    unsigned	ifi_flags;
  30.146 -    unsigned	ifi_change;
  30.147 -  };
  30.148 -*/
  30.149 -class InterfaceInfoMessage : public GeneralMessage
  30.150 -{
  30.151 -public:
  30.152 -  InterfaceInfoMessage ();
  30.153 -  virtual ~InterfaceInfoMessage ();
  30.154 -
  30.155 -  static TypeId GetTypeId (void);
  30.156 -  virtual TypeId GetInstanceTypeId (void) const;
  30.157 -  virtual void Serialize (Buffer::Iterator& start) const;
  30.158 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  30.159 -  virtual void Print (std::ostream &os) const;
  30.160 -  virtual uint32_t GetSerializedSize (void) const;
  30.161 -
  30.162 -  enum IflAttr_e {
  30.163 -    IFL_A_UNSPEC,
  30.164 -    IFL_A_ADDRESS,
  30.165 -    IFL_A_BROADCAST,
  30.166 -    IFL_A_IFNAME,
  30.167 -    IFL_A_MTU,
  30.168 -    IFL_A_LINK,
  30.169 -    IFL_A_QDISC,
  30.170 -    IFL_A_STATS,
  30.171 -    IFL_A_COST,
  30.172 -    IFL_A_PRIORITY,
  30.173 -    IFL_A_MASTER,
  30.174 -    IFL_A_WIRELESS,		
  30.175 -    IFL_A_PROTINFO,
  30.176 -    IFL_A_TXQLEN,
  30.177 -    IFL_A_MAP,
  30.178 -    IFL_A_WEIGHT,
  30.179 -    IFL_A_OPERSTATE,
  30.180 -    IFL_A_LINKMODE,
  30.181 -    IFL_A_MAX,
  30.182 -  };
  30.183 -
  30.184 -  enum Type_e {
  30.185 -    UP = 1,
  30.186 -    BROADCAST = 2,
  30.187 -    DBG = 4,
  30.188 -  };
  30.189 -
  30.190 -  void SetDeviceType (uint16_t type);
  30.191 -  void SetInterfaceIndex (int32_t index);
  30.192 -  void SetDeviceFlags (uint32_t index);
  30.193 -  void SetChangeMask (uint32_t mask);
  30.194 -
  30.195 -  uint16_t GetDeviceType (void) const;
  30.196 -  int32_t GetInterfaceIndex (void) const;
  30.197 -  uint32_t GetDeviceFlags (void) const;
  30.198 -  uint32_t GetChangeMask (void) const;
  30.199 -private:
  30.200 -  static const int NETLINK_INTERFACE_SIZE = 16; /* size of the struct ifinfomsg */
  30.201 -  uint8_t m_reserved; //not used
  30.202 -  uint16_t m_deviceType;
  30.203 -  int32_t m_interfaceIndex;
  30.204 -  uint32_t m_deviceFlags;
  30.205 -  uint32_t m_changeMask;
  30.206 -  NetlinkAttributeValueType m_attributeTypes[IFL_A_MAX];
  30.207 -};
  30.208 -
  30.209 -
  30.210 -
  30.211 -
  30.212 -/**
  30.213 -* \brief Interface address.
  30.214 -*
  30.215 -  struct ifaddrmsg
  30.216 -  {
  30.217 -  unsigned char	ifa_family;
  30.218 -  unsigned char	ifa_prefixlen;
  30.219 -  unsigned char	ifa_flags;
  30.220 -  unsigned char	ifa_scope;
  30.221 -  int		ifa_index;
  30.222 -  };
  30.223 -*/
  30.224 -
  30.225 -class InterfaceAddressMessage : public GeneralMessage
  30.226 -{
  30.227 -public:
  30.228 -  InterfaceAddressMessage ();
  30.229 -  virtual ~InterfaceAddressMessage ();
  30.230 -
  30.231 -  static TypeId GetTypeId (void);
  30.232 -  virtual TypeId GetInstanceTypeId (void) const;
  30.233 -  virtual void Serialize (Buffer::Iterator& start) const;
  30.234 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  30.235 -  virtual void Print (std::ostream &os) const;
  30.236 -  virtual uint32_t GetSerializedSize (void) const;
  30.237 -
  30.238 -  enum IfAttr_e {
  30.239 -    IF_A_UNSPEC,
  30.240 -    IF_A_ADDRESS,
  30.241 -    IF_A_LOCAL,
  30.242 -    IF_A_LABEL,
  30.243 -    IF_A_BROADCAST,
  30.244 -    IF_A_ANYCAST,
  30.245 -    IF_A_CACHEINFO,
  30.246 -    IF_A_MULTICAST,
  30.247 -    IF_A_MAX
  30.248 -  };
  30.249 -
  30.250 -  enum {
  30.251 -    F_SECONDARY = 0x01,
  30.252 -    F_PERMANENT = 0x80,
  30.253 -    F_DEPRECATED = 0x20,
  30.254 -    F_TENTATIVE = 0x40
  30.255 -  };
  30.256 -  enum {
  30.257 -    SCOPE_UNIVERSE = 0,
  30.258 -    SCOPE_SITE = 200,
  30.259 -    SCOPE_LINK = 253,
  30.260 -    SCOPE_HOST = 254
  30.261 -  };
  30.262 -
  30.263 -
  30.264 -  void SetFamily (uint8_t family);
  30.265 -  void SetLength (uint8_t length);
  30.266 -  void SetFlags (uint8_t flags);
  30.267 -  void SetScope (uint8_t scope);
  30.268 -  void SetInterfaceIndex (int32_t index);
  30.269 -
  30.270 -  uint8_t GetFamily (void) const;
  30.271 -  uint8_t GetLength (void) const;
  30.272 -  uint8_t GetFlags (void) const;
  30.273 -  uint8_t GetScope (void) const;
  30.274 -  int32_t GetInterfaceIndex (void) const;
  30.275 -
  30.276 -private:
  30.277 -  static const int NETLINK_ADDRESS_SIZE = 8; /* size of the struct ifaddrmsg */
  30.278 -  uint8_t m_length;
  30.279 -  uint8_t m_flags;
  30.280 -  uint8_t m_scope;
  30.281 -  int32_t m_index;
  30.282 -  NetlinkAttributeValueType m_attributeTypes[IF_A_MAX];
  30.283 -};
  30.284 -
  30.285 -
  30.286 -/**
  30.287 -* \brief Definitions used in routing table administration.
  30.288 -*
  30.289 -  struct rtmsg
  30.290 -  {
  30.291 -    unsigned char		rtm_family;
  30.292 -    unsigned char		rtm_dst_len;
  30.293 -    unsigned char		rtm_src_len;
  30.294 -    unsigned char		rtm_tos;
  30.295 -
  30.296 -    unsigned char		rtm_table;	// Routing table id 
  30.297 -    unsigned char		rtm_protocol;	//Routing protocol; 
  30.298 -    unsigned char		rtm_scope;	
  30.299 -    unsigned char		rtm_type;	
  30.300 -
  30.301 -    unsigned		rtm_flags;
  30.302 -  };
  30.303 -*/
  30.304 -
  30.305 -class RouteMessage : public GeneralMessage
  30.306 -{
  30.307 -public:
  30.308 -  RouteMessage ();
  30.309 -  virtual ~RouteMessage ();
  30.310 -
  30.311 -  static TypeId GetTypeId (void);
  30.312 -  virtual TypeId GetInstanceTypeId (void) const;
  30.313 -  virtual void Serialize (Buffer::Iterator& start) const;
  30.314 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  30.315 -  virtual void Print (std::ostream &os) const;
  30.316 -  virtual uint32_t GetSerializedSize (void) const;
  30.317 -
  30.318 -  uint8_t GetFamily (void) const;
  30.319 -  uint8_t GetDstLength (void) const;
  30.320 -  uint8_t GetSrcLength (void) const;
  30.321 -  uint8_t GetTos (void) const;
  30.322 -  uint8_t GetTableId (void) const;
  30.323 -  uint8_t GetProtocol(void) const;
  30.324 -  uint8_t GetType (void) const;
  30.325 -  uint8_t GetScope (void) const;
  30.326 -  uint32_t GetFlags (void) const;
  30.327 -  void SetFamily (uint8_t v);
  30.328 -  void SetDstLength (uint8_t v);
  30.329 -  void SetSrcLength (uint8_t v);
  30.330 -  void SetTos (uint8_t v);
  30.331 -  void SetTableId (uint8_t v);
  30.332 -  void SetProtocol (uint8_t v);
  30.333 -  void SetScope (uint8_t v);
  30.334 -  void SetType (uint8_t v);
  30.335 -  void SetFlags (uint32_t v);
  30.336 -
  30.337 -  enum RtProtocol_e {
  30.338 -    RT_PROT_UNSPEC = 0,
  30.339 -  };
  30.340 -
  30.341 -  enum RtFlags_e {
  30.342 -    RT_F_CLONED = 0x200,
  30.343 -  };
  30.344 -
  30.345 -  enum RtScope_e {
  30.346 -    RT_SCOPE_UNIVERSE = 0,
  30.347 -    RT_SCOPE_LINK = 253,
  30.348 -  };
  30.349 -
  30.350 -  enum RtClass_e {
  30.351 -    RT_TABLE_UNSPEC = 0,
  30.352 -    RT_TABLE_MAIN = 254,
  30.353 -  };
  30.354 -
  30.355 -  enum RtAttr_e {
  30.356 -    RT_A_UNSPEC,
  30.357 -    RT_A_DST,
  30.358 -    RT_A_SRC,
  30.359 -    RT_A_IIF,
  30.360 -    RT_A_OIF,
  30.361 -    RT_A_GATEWAY,
  30.362 -    RT_A_PRIORITY,
  30.363 -    RT_A_PREFSRC,
  30.364 -    RT_A_METRICS,
  30.365 -    RT_A_MULTIPATH,
  30.366 -    RT_A_PROTOINFO,
  30.367 -    RT_A_FLOW,
  30.368 -    RT_A_CACHEINFO,
  30.369 -    RT_A_SESSION,
  30.370 -    RT_A_MP_ALGO,
  30.371 -    RT_A_TABLE,
  30.372 -    RT_A_MAX
  30.373 -  };
  30.374 -
  30.375 -
  30.376 -private:
  30.377 -  static const int NETLINK_ROUTE_SIZE = 12; /* size of the struct rtmsg */
  30.378 -  uint8_t m_dstLen;
  30.379 -  uint8_t m_srcLen;
  30.380 -  uint8_t m_tos;
  30.381 -  uint8_t m_tableId;
  30.382 -  uint8_t m_protocol;
  30.383 -  uint8_t m_scope;
  30.384 -  uint8_t m_type;
  30.385 -  uint32_t m_flags;
  30.386 -  NetlinkAttributeValueType m_attributeTypes[RT_A_MAX];
  30.387 -};
  30.388 -
  30.389 -}; // namespace ns3
  30.390 -
  30.391 -#endif /* NETLINK_MESSAGE_ROUTE_H */
    31.1 --- a/model/netlink/netlink-message.cc	Mon Apr 18 09:01:30 2011 +0200
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,672 +0,0 @@
    31.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    31.5 -/*
    31.6 - * Copyright (c) 2008 Liu Jian
    31.7 - *
    31.8 - * This program is free software; you can redistribute it and/or modify
    31.9 - * it under the terms of the GNU General Public License version 2 as
   31.10 - * published by the Free Software Foundation;
   31.11 - *
   31.12 - * This program is distributed in the hope that it will be useful,
   31.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   31.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   31.15 - * GNU General Public License for more details.
   31.16 - *
   31.17 - * You should have received a copy of the GNU General Public License
   31.18 - * along with this program; if not, write to the Free Software
   31.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   31.20 - *
   31.21 - * Author: Liu Jian <liujatp@gmail.com>
   31.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   31.23 - */
   31.24 -
   31.25 -#include "netlink-message.h"
   31.26 -#include "ns3/address-utils.h"
   31.27 -#include "ns3/log.h"
   31.28 -
   31.29 -NS_LOG_COMPONENT_DEFINE ("NetlinkMessage");
   31.30 -
   31.31 -namespace ns3 {
   31.32 -
   31.33 -/***********************************************************************************
   31.34 -* \ NetlinkMessageHeader
   31.35 -***********************************************************************************/
   31.36 -NS_OBJECT_ENSURE_REGISTERED (NetlinkMessageHeader);
   31.37 -NS_OBJECT_ENSURE_REGISTERED (NetlinkMessage);
   31.38 -
   31.39 -NetlinkMessageHeader::NetlinkMessageHeader ()
   31.40 -  : m_nlmsgLen (16),
   31.41 -    m_nlmsgType (0),
   31.42 -    m_nlmsgFlags (0),
   31.43 -    m_nlmsgSeq (0),
   31.44 -    m_nlmsgPid (0)
   31.45 -{}
   31.46 -
   31.47 -NetlinkMessageHeader::NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid)
   31.48 -  : m_nlmsgLen (16),
   31.49 -    m_nlmsgType (type),
   31.50 -    m_nlmsgFlags (flags),
   31.51 -    m_nlmsgSeq (seq),
   31.52 -    m_nlmsgPid (pid)
   31.53 -{}
   31.54 -
   31.55 -void
   31.56 -NetlinkMessageHeader::SetMsgLen (uint32_t v)
   31.57 -{
   31.58 -  m_nlmsgLen = v;
   31.59 -}
   31.60 -void
   31.61 -NetlinkMessageHeader::SetMsgFlags (uint16_t v)
   31.62 -{
   31.63 -  m_nlmsgFlags = v;
   31.64 -}
   31.65 -void
   31.66 -NetlinkMessageHeader::SetMsgType (uint16_t v)
   31.67 -{
   31.68 -  m_nlmsgType = v;
   31.69 -}
   31.70 -void
   31.71 -NetlinkMessageHeader::SetMsgSeq (uint32_t v)
   31.72 -{
   31.73 -  m_nlmsgSeq = v;
   31.74 -}
   31.75 -void
   31.76 -NetlinkMessageHeader::SetMsgPid (uint32_t v)
   31.77 -{
   31.78 -  m_nlmsgPid = v;
   31.79 -}
   31.80 -uint16_t
   31.81 -NetlinkMessageHeader::GetMsgFlags (void) const
   31.82 -{
   31.83 -  return m_nlmsgFlags;
   31.84 -}
   31.85 -uint32_t 
   31.86 -NetlinkMessageHeader::GetMsgLen (void) const
   31.87 -{
   31.88 -  return m_nlmsgLen;
   31.89 -}
   31.90 -uint16_t 
   31.91 -NetlinkMessageHeader::GetMsgType (void) const
   31.92 -{
   31.93 -  return m_nlmsgType;
   31.94 -}
   31.95 -uint32_t
   31.96 -NetlinkMessageHeader::GetMsgSeq (void) const
   31.97 -{
   31.98 -  return m_nlmsgSeq;
   31.99 -}
  31.100 -uint32_t 
  31.101 -NetlinkMessageHeader::GetMsgPid (void) const
  31.102 -{
  31.103 -  return m_nlmsgPid;
  31.104 -}
  31.105 -uint32_t
  31.106 -NetlinkMessageHeader::GetHeaderSize ()
  31.107 -{
  31.108 -  return NETLINK_MSG_HEADER_SIZE;
  31.109 -}
  31.110 -uint32_t
  31.111 -NetlinkMessageHeader::GetPayloadSize (void) const
  31.112 -{
  31.113 -  return NETLINK_MSG_ALIGN (m_nlmsgLen - NETLINK_MSG_HEADER_SIZE);
  31.114 -}
  31.115 -
  31.116 -TypeId 
  31.117 -NetlinkMessageHeader::GetTypeId (void)
  31.118 -{
  31.119 -  static TypeId tid = TypeId ("ns3::NetlinkMessageHeader")
  31.120 -    .SetParent<Header> ()
  31.121 -    .AddConstructor<NetlinkMessageHeader> ()
  31.122 -    ;
  31.123 -  return tid;
  31.124 -}
  31.125 -TypeId 
  31.126 -NetlinkMessageHeader::GetInstanceTypeId (void) const
  31.127 -{
  31.128 -  return GetTypeId ();
  31.129 -}
  31.130 -void 
  31.131 -NetlinkMessageHeader::Print (std::ostream &os) const
  31.132 -{
  31.133 -  os << "NetlinkMessageHeader "
  31.134 -     << "len: " << m_nlmsgLen << " "
  31.135 -     << "flags: " << m_nlmsgFlags << " "
  31.136 -     << "type: " << m_nlmsgType << " "
  31.137 -     << "seq: " << m_nlmsgSeq << " "
  31.138 -     << "pid: " << m_nlmsgPid;
  31.139 -}
  31.140 -
  31.141 -uint32_t 
  31.142 -NetlinkMessageHeader::GetSerializedSize (void) const
  31.143 -{
  31.144 -  /* this is the size of an nlmsghdr payload. */
  31.145 -  return NETLINK_MSG_HEADER_SIZE;
  31.146 -}
  31.147 -
  31.148 -void
  31.149 -NetlinkMessageHeader::Serialize (Buffer::Iterator& start) const
  31.150 -{
  31.151 -  start.WriteU32 (m_nlmsgLen);
  31.152 -  start.WriteU16 (m_nlmsgType);
  31.153 -  start.WriteU16 (m_nlmsgFlags);
  31.154 -  start.WriteU32 (m_nlmsgSeq);
  31.155 -  start.WriteU32 (m_nlmsgPid);
  31.156 -}
  31.157 -
  31.158 -uint32_t
  31.159 -NetlinkMessageHeader::Deserialize (Buffer::Iterator& start)
  31.160 -{
  31.161 -  m_nlmsgLen = start.ReadU32 ();
  31.162 -  m_nlmsgType = start.ReadU16 ();
  31.163 -  m_nlmsgFlags = start.ReadU16 ();
  31.164 -  m_nlmsgSeq = start.ReadU32 ();
  31.165 -  m_nlmsgPid = start.ReadU32 ();
  31.166 -
  31.167 -  return GetSerializedSize ();
  31.168 -}
  31.169 -
  31.170 -
  31.171 -
  31.172 -
  31.173 -/***********************************************************************************
  31.174 -* \ NetlinkMessageError
  31.175 -***********************************************************************************/
  31.176 -
  31.177 -NetlinkMessageError::NetlinkMessageError ()
  31.178 -  : m_error (0)
  31.179 -{
  31.180 -}
  31.181 -NetlinkMessageError::~NetlinkMessageError ()
  31.182 -{}
  31.183 -void 
  31.184 -NetlinkMessageError::SetError (int32_t v)
  31.185 -{
  31.186 -  m_error = v;
  31.187 -}
  31.188 -int32_t
  31.189 -NetlinkMessageError::GetError (void) const
  31.190 -{
  31.191 -  return m_error;
  31.192 -}
  31.193 -void
  31.194 -NetlinkMessageError::SetMsg (NetlinkMessageHeader v)
  31.195 -{
  31.196 -  m_msg = v;
  31.197 -}
  31.198 -NetlinkMessageHeader
  31.199 -NetlinkMessageError::GetMsg (void) const
  31.200 -{
  31.201 -  return m_msg;
  31.202 -}
  31.203 -
  31.204 -TypeId 
  31.205 -NetlinkMessageError::GetTypeId (void)
  31.206 -{
  31.207 -  static TypeId tid = TypeId ("ns3::NetlinkMessageError")
  31.208 -    .SetParent<NetlinkPayload> ()
  31.209 -    .AddConstructor<NetlinkMessageError> ()
  31.210 -    ;
  31.211 -  return tid;
  31.212 -}
  31.213 -
  31.214 -TypeId 
  31.215 -NetlinkMessageError::GetInstanceTypeId (void) const
  31.216 -{
  31.217 -  return GetTypeId ();
  31.218 -}
  31.219 -void 
  31.220 -NetlinkMessageError::Print (std::ostream &os) const
  31.221 -{  
  31.222 -  os << "----NetlinkMessageError "
  31.223 -     << "error: " << m_error << " "
  31.224 -     << "msg:( ";
  31.225 -  m_msg.Print(os);
  31.226 -  os << " )";
  31.227 -}
  31.228 -
  31.229 -uint32_t 
  31.230 -NetlinkMessageError::GetSerializedSize (void) const
  31.231 -{
  31.232 -  /* this is the size of an nlmsgerr payload. */
  31.233 -  return NETLINK_MSG_ERROR_SIZE;
  31.234 -}
  31.235 -
  31.236 -void
  31.237 -NetlinkMessageError::Serialize (Buffer::Iterator& start) const
  31.238 -{
  31.239 -  start.WriteU32 (m_error);
  31.240 -  m_msg.Serialize (start);
  31.241 -}
  31.242 -
  31.243 -uint32_t
  31.244 -NetlinkMessageError::Deserialize (Buffer::Iterator& start)
  31.245 -{  
  31.246 -  m_error = start.ReadU32 ();
  31.247 -  m_msg.Deserialize (start);
  31.248 -  
  31.249 -  return GetSerializedSize ();
  31.250 -}
  31.251 -
  31.252 -
  31.253 -
  31.254 -
  31.255 -/***********************************************************************************
  31.256 -* \ NetlinkMessage
  31.257 -***********************************************************************************/
  31.258 -NetlinkMessage::NetlinkMessage ()
  31.259 -{}
  31.260 -
  31.261 -void
  31.262 -NetlinkMessage::SetHeader (NetlinkMessageHeader hdr)
  31.263 -{
  31.264 -  m_hdr = hdr;
  31.265 -}
  31.266 -NetlinkMessageHeader
  31.267 -NetlinkMessage::GetHeader (void)const
  31.268 -{
  31.269 -  return m_hdr;
  31.270 -}
  31.271 -void
  31.272 -NetlinkMessage::SetGeneralMessage (GeneralMessage genmsg)
  31.273 -{
  31.274 -  m_genmsg = genmsg;
  31.275 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + genmsg.GetSerializedSize ());
  31.276 -}
  31.277 -void
  31.278 -NetlinkMessage::SetErrorMessage (NetlinkMessageError errmsg)
  31.279 -{
  31.280 -  m_errorMessage = errmsg;
  31.281 -  m_hdr.SetMsgLen(m_hdr.GetSerializedSize () + errmsg.GetSerializedSize ());
  31.282 -}
  31.283 -// the type is one of RTM_NEWLINK,RTM_DELLINK,RTM_GETLINK
  31.284 -void
  31.285 -NetlinkMessage::SetInterfaceInfoMessage (InterfaceInfoMessage v)
  31.286 -{
  31.287 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  31.288 -  m_interfaceTemplate = v;
  31.289 -}
  31.290 -// the type is one of RTM_NEWADDR,RTM_DELADDR,RTM_GETADDR
  31.291 -void NetlinkMessage::SetInterfaceAddressMessage (InterfaceAddressMessage v)
  31.292 -{
  31.293 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  31.294 -  m_addressTemplate = v;
  31.295 -}
  31.296 -// the type  is one of RTM_NEWROUTE,RTM_DELROUTE,RTM_GETROUTE
  31.297 -void NetlinkMessage::SetRouteMessage (RouteMessage v)
  31.298 -{
  31.299 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  31.300 -  m_routeTemplate = v;
  31.301 -}
  31.302 -GeneralMessage
  31.303 -NetlinkMessage::GetGeneralMessage (void) const
  31.304 -{
  31.305 -  return m_genmsg;
  31.306 -}
  31.307 -NetlinkMessageError
  31.308 -NetlinkMessage::GetErrorMessage (void) const
  31.309 -{
  31.310 -  return m_errorMessage;
  31.311 -}
  31.312 -InterfaceInfoMessage
  31.313 -NetlinkMessage::GetInterfaceInfoMessage (void) const
  31.314 -{
  31.315 -  return m_interfaceTemplate;
  31.316 -}
  31.317 -InterfaceAddressMessage
  31.318 -NetlinkMessage::GetInterfaceAddressMessage (void) const
  31.319 -{
  31.320 -  return m_addressTemplate;
  31.321 -}
  31.322 -RouteMessage
  31.323 -NetlinkMessage::GetRouteMessage (void) const
  31.324 -{
  31.325 -  return m_routeTemplate;
  31.326 -}
  31.327 -bool
  31.328 -NetlinkMessage::IsMessageNetlinkControl (uint16_t type)
  31.329 -{
  31.330 -  return (type < NETLINK_RTM_BASE);
  31.331 -}
  31.332 -bool
  31.333 -NetlinkMessage::IsMessageNetlinkRoute (uint16_t type)
  31.334 -{
  31.335 -  return (type >= NETLINK_RTM_BASE && type < NETLINK_RTM_MAX);
  31.336 -}
  31.337 -bool
  31.338 -NetlinkMessage::IsMessageAddress (uint16_t type)
  31.339 -{
  31.340 -  return (type >= NETLINK_RTM_NEWADDR && type <= NETLINK_RTM_GETADDR);
  31.341 -}
  31.342 -bool
  31.343 -NetlinkMessage::IsMessageInterface (uint16_t type)
  31.344 -{
  31.345 -  return (type >= NETLINK_RTM_NEWLINK && type <= NETLINK_RTM_SETLINK);
  31.346 -}
  31.347 -bool
  31.348 -NetlinkMessage::IsMessageRoute (uint16_t type)
  31.349 -{
  31.350 -  return (type >= NETLINK_RTM_NEWROUTE && type <= NETLINK_RTM_GETROUTE);
  31.351 -}
  31.352 -bool
  31.353 -NetlinkMessage::IsMessageTypeGet (uint16_t type)
  31.354 -{
  31.355 -  return ((( type - NETLINK_RTM_BASE)&3) == 2);
  31.356 -}
  31.357 -bool
  31.358 -NetlinkMessage::IsMessageFlagsAck (uint16_t flags)
  31.359 -{
  31.360 -  return (flags & NETLINK_MSG_F_ACK) ? true : false;
  31.361 -}
  31.362 -bool
  31.363 -NetlinkMessage::IsMessageFlagsRequest (uint16_t flags)
  31.364 -{
  31.365 -  return (flags & NETLINK_MSG_F_REQUEST) ? true : false;
  31.366 -}
  31.367 -bool
  31.368 -NetlinkMessage::IsMessageFlagsDump (uint16_t flags)
  31.369 -{
  31.370 -  return (flags & NETLINK_MSG_F_DUMP) ? true : false;
  31.371 -}
  31.372 -
  31.373 -NetlinkMessage::operator MultipartNetlinkMessage (void) const
  31.374 -{
  31.375 -  MultipartNetlinkMessage multi_nlmsg;
  31.376 -  multi_nlmsg.AppendMessage (*this);
  31.377 -  return multi_nlmsg;
  31.378 -}
  31.379 -
  31.380 -TypeId 
  31.381 -NetlinkMessage::GetTypeId (void)
  31.382 -{
  31.383 -  static TypeId tid = TypeId ("ns3::NetlinkMessage")
  31.384 -    .SetParent<Header> ()
  31.385 -    .AddConstructor<NetlinkMessage> ()
  31.386 -    ;
  31.387 -  return tid;
  31.388 -}
  31.389 -TypeId 
  31.390 -NetlinkMessage::GetInstanceTypeId (void) const
  31.391 -{
  31.392 -  return GetTypeId ();
  31.393 -}
  31.394 -
  31.395 -uint32_t
  31.396 -NetlinkMessage::GetTotalSize (void) const
  31.397 -{
  31.398 -  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
  31.399 -}
  31.400 -
  31.401 -uint32_t
  31.402 -NetlinkMessage::GetMsgSize (void) const
  31.403 -{
  31.404 -  return m_hdr.GetMsgLen ();
  31.405 -}
  31.406 -
  31.407 -uint32_t
  31.408 -NetlinkMessage::GetPayloadSize (void) const
  31.409 -{
  31.410 -  return m_hdr.GetPayloadSize ();
  31.411 -}
  31.412 -uint16_t
  31.413 -NetlinkMessage::GetMsgType (void) const
  31.414 -{
  31.415 -  return m_hdr.GetMsgType ();
  31.416 -}
  31.417 -
  31.418 -uint8_t
  31.419 -NetlinkMessage::GetFamily(void) const
  31.420 -{
  31.421 -  if (IsMessageTypeGet (GetMsgType ()))
  31.422 -    {
  31.423 -      NS_LOG_DEBUG ("TypeGetMsg");
  31.424 -    }
  31.425 -  if (IsMessageAddress (m_hdr.GetMsgType ()))
  31.426 -    {
  31.427 -      return m_addressTemplate.GetFamily ();
  31.428 -    }
  31.429 -  else if (IsMessageInterface(m_hdr.GetMsgType ()))
  31.430 -    {
  31.431 -      return m_interfaceTemplate.GetFamily ();
  31.432 -    }
  31.433 -  else if (IsMessageRoute(m_hdr.GetMsgType ()))
  31.434 -    {
  31.435 -      return m_routeTemplate.GetFamily ();
  31.436 -    }
  31.437 -  else if (IsMessageFlagsDump (m_hdr.GetMsgFlags ()))
  31.438 -    {
  31.439 -      return m_genmsg.GetFamily (); //value is said to be always set to AF_UNSPEC
  31.440 -    }
  31.441 -  else
  31.442 -    {
  31.443 -      NS_LOG_WARN ("Netlink message type not supported, return AF_UNSPEC");
  31.444 -      return 0;
  31.445 -    }
  31.446 -}
  31.447 -
  31.448 -void 
  31.449 -NetlinkMessage::Print (std::ostream &os) const
  31.450 -{
  31.451 -  uint16_t type = m_hdr.GetMsgType ();
  31.452 -
  31.453 -  os << "NetlinkMessage  ";
  31.454 -  os << " ----Header:(";
  31.455 -  m_hdr.Print(os);
  31.456 -  os << ")";
  31.457 -
  31.458 -  if (type == NETLINK_MSG_DONE )
  31.459 -    {
  31.460 -      os << "multipart message ends here";
  31.461 -    }
  31.462 -  else if (type == NETLINK_MSG_ERROR )
  31.463 -    {
  31.464 -      m_errorMessage.Print (os);
  31.465 -    }
  31.466 -  else if (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK)
  31.467 -    {
  31.468 -      m_genmsg.Print (os);
  31.469 -    }  
  31.470 -  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE)
  31.471 -    {
  31.472 -      m_routeTemplate.Print (os);
  31.473 -    }
  31.474 -  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  31.475 -    {
  31.476 -      m_addressTemplate.Print (os);
  31.477 -    }
  31.478 -  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_DELLINK)
  31.479 -    {
  31.480 -      m_interfaceTemplate.Print (os);
  31.481 -    }
  31.482 -  else
  31.483 -    {
  31.484 -      os << "service not supported yet( " << type <<")";
  31.485 -    }
  31.486 -}
  31.487 -uint32_t 
  31.488 -NetlinkMessage::GetSerializedSize (void) const
  31.489 -{
  31.490 -  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
  31.491 -}
  31.492 -
  31.493 -void
  31.494 -NetlinkMessage::Serialize (Buffer::Iterator& start) const
  31.495 -{
  31.496 -  NS_LOG_FUNCTION (this);
  31.497 -  //  Print (std::cout);
  31.498 -  uint16_t type = m_hdr.GetMsgType ();
  31.499 -
  31.500 -  m_hdr.Serialize (start);
  31.501 -
  31.502 -  if (type == NETLINK_MSG_DONE)
  31.503 -    {
  31.504 -      //nothing done
  31.505 -    }
  31.506 -  else if (type == NETLINK_MSG_ERROR)
  31.507 -    {
  31.508 -      m_errorMessage.Serialize (start);
  31.509 -    }  
  31.510 -  else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags ()) && 
  31.511 -           (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
  31.512 -    {
  31.513 -      m_genmsg.Serialize (start);
  31.514 -    }  
  31.515 -  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  31.516 -    {
  31.517 -      m_routeTemplate.Serialize (start);
  31.518 -    }
  31.519 -  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  31.520 -    {
  31.521 -      m_addressTemplate.Serialize (start);
  31.522 -    }
  31.523 -  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
  31.524 -    {
  31.525 -      m_interfaceTemplate.Serialize (start);
  31.526 -    }
  31.527 -  else
  31.528 -    {
  31.529 -    }  
  31.530 -}
  31.531 -
  31.532 -
  31.533 -uint32_t
  31.534 -NetlinkMessage::Deserialize (Buffer::Iterator&start)
  31.535 -{
  31.536 -  uint32_t remaining;
  31.537 -
  31.538 -  m_hdr.Deserialize (start);
  31.539 -  remaining = NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ()) - m_hdr.GetSerializedSize ();
  31.540 -  
  31.541 -  //Deserialize service module
  31.542 -  uint16_t type = GetMsgType ();
  31.543 -  if (remaining)
  31.544 -    {        
  31.545 -      if (type == NETLINK_MSG_DONE)
  31.546 -        {
  31.547 -          //do nothing
  31.548 -        }
  31.549 -      else if (type == NETLINK_MSG_ERROR)
  31.550 -        {
  31.551 -          remaining -= m_errorMessage.Deserialize (start);
  31.552 -        }      
  31.553 -      else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags()) &&
  31.554 -               (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
  31.555 -        {
  31.556 -          remaining -= m_genmsg.Deserialize (start, remaining);
  31.557 -        }
  31.558 -      else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  31.559 -        {
  31.560 -          remaining -= m_routeTemplate.Deserialize (start, remaining);
  31.561 -        }
  31.562 -      else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  31.563 -        {
  31.564 -          remaining -= m_addressTemplate.Deserialize (start, remaining);
  31.565 -        }
  31.566 -      else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
  31.567 -        {
  31.568 -          remaining -= m_interfaceTemplate.Deserialize (start, remaining);
  31.569 -        }
  31.570 -      else
  31.571 -        {
  31.572 -          //do nothing
  31.573 -        }
  31.574 -    }
  31.575 -
  31.576 -  return GetSerializedSize ();
  31.577 -}
  31.578 -
  31.579 -
  31.580 -/***********************************************************************************
  31.581 -* \ MultipartNetlinkMessage
  31.582 -***********************************************************************************/
  31.583 -MultipartNetlinkMessage::MultipartNetlinkMessage ()
  31.584 -{}
  31.585 -
  31.586 -TypeId 
  31.587 -MultipartNetlinkMessage::GetTypeId (void)
  31.588 -{
  31.589 -  static TypeId tid = TypeId ("ns3::MultipartNetlinkMessage")
  31.590 -    .SetParent<Header> ()
  31.591 -    .AddConstructor<MultipartNetlinkMessage> ()
  31.592 -    ;
  31.593 -  return tid;
  31.594 -}
  31.595 -TypeId 
  31.596 -MultipartNetlinkMessage::GetInstanceTypeId (void) const
  31.597 -{
  31.598 -  return GetTypeId ();
  31.599 -}
  31.600 -
  31.601 -void
  31.602 -MultipartNetlinkMessage::Print (std::ostream &os) const
  31.603 -{
  31.604 -  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  31.605 -    {
  31.606 -      m_netlinkMessages[i].Print (os);
  31.607 -    }
  31.608 -}
  31.609 -uint32_t
  31.610 -MultipartNetlinkMessage::GetSerializedSize (void) const
  31.611 -{
  31.612 -  uint32_t len = 0;
  31.613 -
  31.614 -  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  31.615 -    {
  31.616 -      len +=  m_netlinkMessages[i].GetSerializedSize ();
  31.617 -    }
  31.618 -  return len;
  31.619 -}
  31.620 -void
  31.621 -MultipartNetlinkMessage::Serialize (Buffer::Iterator start) const
  31.622 -{
  31.623 -  NS_LOG_FUNCTION ("Multi" << this);
  31.624 -  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  31.625 -    {
  31.626 -      m_netlinkMessages[i].Serialize (start);
  31.627 -    }
  31.628 -}
  31.629 -uint32_t
  31.630 -MultipartNetlinkMessage::Deserialize (Buffer::Iterator start)
  31.631 -{
  31.632 -  while (1)
  31.633 -    {
  31.634 -      NetlinkMessage nlmsg;
  31.635 -      nlmsg.Deserialize (start);
  31.636 -      AppendMessage (nlmsg);
  31.637 -
  31.638 -      if (!(nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_MULTI))
  31.639 -        {
  31.640 -          break;
  31.641 -        }
  31.642 -
  31.643 -      if (nlmsg.GetHeader ().GetMsgType() == NETLINK_MSG_DONE)
  31.644 -        {
  31.645 -          break;
  31.646 -        }
  31.647 -    }
  31.648 -  return GetSerializedSize ();
  31.649 -}
  31.650 -
  31.651 -void
  31.652 -MultipartNetlinkMessage::AppendMessage (NetlinkMessage nlmsg)
  31.653 -{
  31.654 -  m_netlinkMessages.push_back (nlmsg);
  31.655 -}
  31.656 -
  31.657 -void
  31.658 -MultipartNetlinkMessage::Clear ()
  31.659 -{
  31.660 -  m_netlinkMessages.clear ();
  31.661 -}
  31.662 -
  31.663 -uint32_t
  31.664 -MultipartNetlinkMessage::GetNMessages (void) const
  31.665 -{
  31.666 -  return m_netlinkMessages.size ();
  31.667 -}
  31.668 -NetlinkMessage
  31.669 -MultipartNetlinkMessage::GetMessage (uint32_t index) const
  31.670 -{
  31.671 -  NS_ASSERT(index < m_netlinkMessages.size ());
  31.672 -  return m_netlinkMessages[index];
  31.673 -}
  31.674 -
  31.675 -}; // namespace ns3
    32.1 --- a/model/netlink/netlink-message.h	Mon Apr 18 09:01:30 2011 +0200
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,256 +0,0 @@
    32.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    32.5 -/*
    32.6 - * Copyright (c) 2008 Liu Jian
    32.7 - *
    32.8 - * This program is free software; you can redistribute it and/or modify
    32.9 - * it under the terms of the GNU General Public License version 2 as
   32.10 - * published by the Free Software Foundation;
   32.11 - *
   32.12 - * This program is distributed in the hope that it will be useful,
   32.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   32.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   32.15 - * GNU General Public License for more details.
   32.16 - *
   32.17 - * You should have received a copy of the GNU General Public License
   32.18 - * along with this program; if not, write to the Free Software
   32.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   32.20 - *
   32.21 - * Author: Liu Jian <liujatp@gmail.com>
   32.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   32.23 - */
   32.24 -
   32.25 -#ifndef NETLINK_MESSAGE_H
   32.26 -#define NETLINK_MESSAGE_H
   32.27 -
   32.28 -#include "ns3/header.h"
   32.29 -#include "ns3/address.h"
   32.30 -#include "netlink-message-route.h"
   32.31 -#include "netlink-attribute.h"
   32.32 -
   32.33 -
   32.34 -namespace ns3 {
   32.35 -  class NetlinkPayload;
   32.36 -  class GeneralMessage;
   32.37 -  class InterfaceAddressMessage;
   32.38 -  class InterfaceInfoMessage;
   32.39 -  class RouteMessage;
   32.40 -  class MultipartNetlinkMessage;
   32.41 -
   32.42 -/**
   32.43 -* \brief The Netlink message structure for an netlink packet
   32.44 -* 
   32.45 -There are three levels to a Netlink message: The general Netlink
   32.46 -message header, the IP service specific template, and the IP service
   32.47 -specific data.
   32.48 -
   32.49 -0                   1                   2                   3
   32.50 -0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   32.51 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   32.52 -|                                                               |
   32.53 -|                   Netlink message header                      |
   32.54 -|                                                               |
   32.55 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   32.56 -|                                                               |
   32.57 -|                  IP Service Template                          |
   32.58 -|                                                               |
   32.59 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   32.60 -|                                                               |
   32.61 -|                  IP Service specific data in TLVs             |
   32.62 -|                                                               |
   32.63 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   32.64 -*/
   32.65 -
   32.66 -  enum NetlinkMessageFlag
   32.67 -  {
   32.68 -    NETLINK_MSG_F_REQUEST = 1,  // It is request message.
   32.69 -    NETLINK_MSG_F_MULTI = 2,    // Multipart message, terminated by NETLINK_MSG_DONE
   32.70 -    NETLINK_MSG_F_ACK = 4,      // Reply with ack, with zero or error code
   32.71 -    NETLINK_MSG_F_ECHO = 8,     // Echo this request 
   32.72 -
   32.73 -    /* Modifiers to Get request */
   32.74 -    NETLINK_MSG_F_ROOT = 0x100,        // specify tree root
   32.75 -    NETLINK_MSG_F_MATCH = 0x200,       // return all matching
   32.76 -    NETLINK_MSG_F_ATOMIC = 0x400,      // atomic Get =
   32.77 -    NETLINK_MSG_F_DUMP = (NETLINK_MSG_F_ROOT|NETLINK_MSG_F_MATCH),
   32.78 -
   32.79 -    /* Modifiers to NEW request */
   32.80 -    NETLINK_MSG_F_REPLACE = 0x100, // Override existing = 
   32.81 -    NETLINK_MSG_F_EXCL = 0x200,   // Do not touch, if it exists
   32.82 -    NETLINK_MSG_F_CREATE = 0x400,  // Create, if it does not exist
   32.83 -    NETLINK_MSG_F_APPEND = 0x800,  // Add to end of list = 
   32.84 -  };
   32.85 -
   32.86 -  enum NetlinkMessageType
   32.87 -  {
   32.88 -    NETLINK_MSG_NOOP = 0x1,          // Nothing.
   32.89 -    NETLINK_MSG_ERROR = 0x2,         // Error
   32.90 -    NETLINK_MSG_DONE = 0x3,          // End of a dump
   32.91 -    NETLINK_MSG_OVERRUN = 0x4,       // Data lost
   32.92 -    NETLINK_MSG_MIN_TYPE = 0x10,     // < 0x10: reserved control messages
   32.93 -  };
   32.94 -
   32.95 -#define NETLINK_MSG_ALIGNTO 4
   32.96 -#define NETLINK_MSG_ALIGN(X)    (((X)+NETLINK_MSG_ALIGNTO-1) & ~(NETLINK_MSG_ALIGNTO-1) )
   32.97 -
   32.98 -class NetlinkMessageHeader : public ObjectBase
   32.99 -{
  32.100 -public:
  32.101 -  NetlinkMessageHeader ();
  32.102 -  NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid);
  32.103 -
  32.104 -  static TypeId GetTypeId (void);
  32.105 -  virtual TypeId GetInstanceTypeId (void) const;
  32.106 -  void Print (std::ostream &os) const;
  32.107 -  uint32_t GetSerializedSize (void) const;
  32.108 -  void Serialize (Buffer::Iterator& start) const;
  32.109 -  uint32_t Deserialize (Buffer::Iterator& start);
  32.110 -
  32.111 -  void SetMsgLen (uint32_t v);
  32.112 -  void SetMsgFlags (uint16_t v);
  32.113 -  void SetMsgType (uint16_t v);
  32.114 -  void SetMsgSeq (uint32_t v);
  32.115 -  void SetMsgPid (uint32_t v);
  32.116 -  uint32_t GetMsgLen (void) const;
  32.117 -  uint16_t GetMsgFlags (void) const;
  32.118 -  uint16_t GetMsgType (void) const;
  32.119 -  uint32_t GetMsgSeq (void) const;
  32.120 -  uint32_t GetMsgPid (void) const;
  32.121 -
  32.122 -  static uint32_t GetHeaderSize ();
  32.123 -  uint32_t GetPayloadSize (void) const;
  32.124 -
  32.125 -private:
  32.126 -  static const uint32_t NETLINK_MSG_HEADER_SIZE = 16; /* size of the nlmsghdr field*/
  32.127 -  uint32_t m_nlmsgLen;	/* Length of message including header */
  32.128 -  uint16_t m_nlmsgType;	/* Message content */
  32.129 -  uint16_t m_nlmsgFlags;	/* Additional flags */
  32.130 -  uint32_t m_nlmsgSeq;	/* Sequence number */
  32.131 -  uint32_t m_nlmsgPid;	/* Sending process PID */
  32.132 -};
  32.133 -
  32.134 -/**
  32.135 -* \brief The struct nlmsgerr
  32.136 -*/
  32.137 -class NetlinkMessageError : public NetlinkPayload
  32.138 -{
  32.139 -public:
  32.140 -  NetlinkMessageError ();
  32.141 -  virtual ~NetlinkMessageError();
  32.142 -
  32.143 -  static TypeId GetTypeId (void);
  32.144 -  virtual TypeId GetInstanceTypeId (void) const;
  32.145 -  virtual void Serialize (Buffer::Iterator& start) const;
  32.146 -  virtual uint32_t Deserialize (Buffer::Iterator& start);
  32.147 -  virtual void Print (std::ostream &os) const;
  32.148 -  virtual uint32_t GetSerializedSize (void) const;
  32.149 -
  32.150 -  void SetError (int32_t v);
  32.151 -  int32_t GetError (void) const;
  32.152 -  void SetMsg(NetlinkMessageHeader v);
  32.153 -  NetlinkMessageHeader GetMsg (void) const;
  32.154 -
  32.155 -private:
  32.156 -  static const int NETLINK_MSG_ERROR_SIZE = 20; /* size of the nlmsgerror field*/
  32.157 -  int32_t m_error;
  32.158 -  NetlinkMessageHeader m_msg;        
  32.159 -};
  32.160 -
  32.161 -
  32.162 -class NetlinkMessage : public ObjectBase
  32.163 -{
  32.164 -public:
  32.165 -  NetlinkMessage ();
  32.166 -
  32.167 -  static TypeId GetTypeId (void);
  32.168 -  TypeId GetInstanceTypeId (void) const;
  32.169 -  void Print (std::ostream &os) const;
  32.170 -  uint32_t GetSerializedSize (void) const;
  32.171 -  void Serialize (Buffer::Iterator& start) const;
  32.172 -  uint32_t Deserialize (Buffer::Iterator& start);
  32.173 -
  32.174 -  operator MultipartNetlinkMessage (void) const;
  32.175 -
  32.176 -  uint32_t GetTotalSize (void) const;  //length of netlink message including padding
  32.177 -  uint32_t GetMsgSize (void) const;    //length of netlink message not including padding
  32.178 -  uint32_t GetPayloadSize (void) const; //length of message payload
  32.179 -  uint16_t GetMsgType (void) const;
  32.180 -  uint8_t GetFamily(void) const;
  32.181 -
  32.182 -  void SetHeader (NetlinkMessageHeader hdr);
  32.183 -  NetlinkMessageHeader GetHeader (void) const;
  32.184 -
  32.185 -  //before set message body, should set header first
  32.186 -  void SetErrorMessage (NetlinkMessageError errmsg);
  32.187 -  void SetGeneralMessage (GeneralMessage genmsg);
  32.188 -  void SetInterfaceInfoMessage (InterfaceInfoMessage v);
  32.189 -  void SetInterfaceAddressMessage (InterfaceAddressMessage v);
  32.190 -  void SetRouteMessage (RouteMessage v);
  32.191 -  NetlinkMessageError GetErrorMessage (void) const;
  32.192 -  GeneralMessage GetGeneralMessage (void) const;
  32.193 -  InterfaceInfoMessage GetInterfaceInfoMessage (void) const;
  32.194 -  InterfaceAddressMessage GetInterfaceAddressMessage (void) const;
  32.195 -  RouteMessage GetRouteMessage (void) const;
  32.196 -
  32.197 -  /**
  32.198 -  * \returns true if type was control type, false otherwise.
  32.199 -  */
  32.200 -  static bool IsMessageNetlinkControl (uint16_t type);
  32.201 -  /**
  32.202 -  * \returns true if type was netlink route, false otherwise.
  32.203 -  */
  32.204 -  static bool IsMessageNetlinkRoute (uint16_t type);
  32.205 -  static bool IsMessageAddress (uint16_t type);
  32.206 -  static bool IsMessageInterface (uint16_t type);
  32.207 -  static bool IsMessageRoute (uint16_t type);
  32.208 -  /**
  32.209 -  * \returns true if type was GETxxx , false otherwise.
  32.210 -  */
  32.211 -  static bool IsMessageTypeGet (uint16_t type);
  32.212 -  /**
  32.213 -  * \returns true if flag has ack , false otherwise.
  32.214 -  */
  32.215 -  static bool IsMessageFlagsAck (uint16_t flags);
  32.216 -  /**
  32.217 -  * \returns true if flag has request , false otherwise.
  32.218 -  */
  32.219 -  static bool IsMessageFlagsRequest (uint16_t flags);
  32.220 -  /**
  32.221 -  * \returns true if flag has dump , false otherwise.
  32.222 -  */
  32.223 -  static bool IsMessageFlagsDump (uint16_t flags);
  32.224 -
  32.225 -private:
  32.226 -  NetlinkMessageHeader m_hdr;
  32.227 -
  32.228 -  //only one type of messages below exists in real world application
  32.229 -  NetlinkMessageError m_errorMessage;  
  32.230 -  GeneralMessage m_genmsg;
  32.231 -  InterfaceInfoMessage m_interfaceTemplate;
  32.232 -  InterfaceAddressMessage m_addressTemplate;
  32.233 -  RouteMessage m_routeTemplate;
  32.234 -};
  32.235 -
  32.236 -class MultipartNetlinkMessage : public Header
  32.237 -{
  32.238 -public:
  32.239 -  MultipartNetlinkMessage ();
  32.240 -
  32.241 -  static TypeId GetTypeId (void);
  32.242 -  virtual TypeId GetInstanceTypeId (void) const;
  32.243 -  virtual void Print (std::ostream &os) const;
  32.244 -  virtual uint32_t GetSerializedSize (void) const;
  32.245 -  virtual void Serialize (Buffer::Iterator start) const;
  32.246 -  virtual uint32_t Deserialize (Buffer::Iterator start);
  32.247 -
  32.248 -  void AppendMessage (NetlinkMessage nlmsg);
  32.249 -  void Clear();
  32.250 -  uint32_t GetNMessages (void) const;
  32.251 -  NetlinkMessage GetMessage (uint32_t index) const;
  32.252 -
  32.253 -private:
  32.254 -  std::vector<NetlinkMessage> m_netlinkMessages;
  32.255 -};
  32.256 -
  32.257 -}; // namespace ns3
  32.258 -
  32.259 -#endif /* NETLINK_MESSAGE_H */
    33.1 --- a/model/netlink/netlink-socket-address.cc	Mon Apr 18 09:01:30 2011 +0200
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,121 +0,0 @@
    33.4 -/* -*-	Mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    33.5 -/*
    33.6 - * Copyright (c) 2008 Liu Jian
    33.7 - *
    33.8 - * This program is free software; you can redistribute it and/or modify
    33.9 - * it under the terms of the GNU General Public License version 2 as
   33.10 - * published by the Free Software Foundation;
   33.11 - *
   33.12 - * This program is distributed in the hope that it will be useful,
   33.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   33.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   33.15 - * GNU General Public License for more details.
   33.16 - *
   33.17 - * You should have received a copy of the GNU General Public License
   33.18 - * along with this program; if not, write to the Free Software
   33.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   33.20 - *
   33.21 - * Author: Liu Jian <liujatp@gmail.com>
   33.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   33.23 - */
   33.24 -
   33.25 -#include "netlink-socket-address.h"
   33.26 -
   33.27 -namespace ns3 {
   33.28 -
   33.29 -NetlinkSocketAddress::NetlinkSocketAddress (uint32_t pid, uint32_t groups)
   33.30 -  : m_pid(pid),
   33.31 -    m_groups(groups)
   33.32 -{}
   33.33 -
   33.34 -NetlinkSocketAddress::NetlinkSocketAddress ()
   33.35 -  : m_pid (0),
   33.36 -    m_groups (0)
   33.37 -{}
   33.38 -
   33.39 -NetlinkSocketAddress::~NetlinkSocketAddress ()
   33.40 -{}
   33.41 -
   33.42 -void NetlinkSocketAddress::SetProcessID (uint32_t pid)
   33.43 -{
   33.44 -  m_pid = pid;
   33.45 -}
   33.46 -
   33.47 -void NetlinkSocketAddress::SetGroupsMask (uint32_t mask)
   33.48 -{
   33.49 -  m_groups = mask;
   33.50 -}
   33.51 -
   33.52 -uint32_t NetlinkSocketAddress::GetProcessID (void) const
   33.53 -{
   33.54 -  return m_pid;
   33.55 -}
   33.56 -
   33.57 -uint32_t NetlinkSocketAddress::GetGroupsMask (void) const
   33.58 -{
   33.59 -  return m_groups;
   33.60 -}
   33.61 -
   33.62 -NetlinkSocketAddress::operator Address (void) const
   33.63 -{
   33.64 -  return ConvertTo ();
   33.65 -}
   33.66 -
   33.67 -Address NetlinkSocketAddress::ConvertTo (void) const
   33.68 -{
   33.69 -  uint8_t buffer[8];
   33.70 -
   33.71 -  buffer[0] = (m_pid >> 24) & 0xff;
   33.72 -  buffer[1] = (m_pid >> 16) & 0xff;
   33.73 -  buffer[2] = (m_pid >> 8) & 0xff;
   33.74 -  buffer[3] = (m_pid >> 0) & 0xff;
   33.75 -  buffer[4] = (m_groups >> 24) & 0xff;
   33.76 -  buffer[5] = (m_groups >> 16) & 0xff;
   33.77 -  buffer[6] = (m_groups >> 8) & 0xff;
   33.78 -  buffer[7] = (m_groups >> 0) & 0xff;
   33.79 -
   33.80 -  return Address (GetType (), buffer, 8);
   33.81 -}
   33.82 -
   33.83 -NetlinkSocketAddress NetlinkSocketAddress::ConvertFrom (const Address &address)
   33.84 -{
   33.85 -  NS_ASSERT (IsMatchingType (address));
   33.86 -
   33.87 -  NetlinkSocketAddress nl;
   33.88 -  uint8_t buf[8];
   33.89 -
   33.90 -  address.CopyTo (buf);
   33.91 -
   33.92 -  nl.m_pid = 0;
   33.93 -  nl.m_pid |= buf[0];
   33.94 -  nl.m_pid <<= 8;
   33.95 -  nl.m_pid |= buf[1];
   33.96 -  nl.m_pid <<= 8;
   33.97 -  nl.m_pid |= buf[2];
   33.98 -  nl.m_pid <<= 8;
   33.99 -  nl.m_pid |= buf[3];
  33.100 -
  33.101 -  nl.m_groups = 0;
  33.102 -  nl.m_groups |= buf[4];
  33.103 -  nl.m_groups <<= 8;
  33.104 -  nl.m_groups |= buf[5];
  33.105 -  nl.m_groups <<= 8;
  33.106 -  nl.m_groups |= buf[6];
  33.107 -  nl.m_groups <<= 8;
  33.108 -  nl.m_groups |= buf[7];
  33.109 -
  33.110 -  return nl;
  33.111 -}
  33.112 -
  33.113 -bool NetlinkSocketAddress::IsMatchingType (const Address &address)
  33.114 -{
  33.115 -  return address.IsMatchingType (GetType ());
  33.116 -}
  33.117 -
  33.118 -uint8_t NetlinkSocketAddress::GetType (void)
  33.119 -{
  33.120 -  static uint8_t type = Address::Register ();
  33.121 -  return type;
  33.122 -}
  33.123 -
  33.124 -} // namespace ns3
    34.1 --- a/model/netlink/netlink-socket-address.h	Mon Apr 18 09:01:30 2011 +0200
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,71 +0,0 @@
    34.4 -/* -*-	Mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    34.5 -/*
    34.6 - * Copyright (c) 2008 Liu Jian
    34.7 - *
    34.8 - * This program is free software; you can redistribute it and/or modify
    34.9 - * it under the terms of the GNU General Public License version 2 as
   34.10 - * published by the Free Software Foundation;
   34.11 - *
   34.12 - * This program is distributed in the hope that it will be useful,
   34.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   34.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   34.15 - * GNU General Public License for more details.
   34.16 - *
   34.17 - * You should have received a copy of the GNU General Public License
   34.18 - * along with this program; if not, write to the Free Software
   34.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   34.20 - *
   34.21 - * Author: Liu Jian <liujatp@gmail.com>
   34.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   34.23 - */
   34.24 -
   34.25 -#ifndef NETLINK_SOCKET_ADDRESS_H
   34.26 -#define NETLINK_SOCKET_ADDRESS_H
   34.27 -
   34.28 -#include "ns3/ptr.h"
   34.29 -#include "ns3/address.h"
   34.30 -
   34.31 -namespace ns3 {
   34.32 -
   34.33 -class NetlinkSocketAddress
   34.34 -{
   34.35 -public:
   34.36 -  NetlinkSocketAddress (uint32_t pid, uint32_t groups);
   34.37 -  NetlinkSocketAddress ();
   34.38 -  ~NetlinkSocketAddress ();
   34.39 -
   34.40 -  void SetProcessID (uint32_t pid);
   34.41 -  void SetGroupsMask (uint32_t mask);
   34.42 -
   34.43 -  uint32_t GetProcessID (void) const;
   34.44 -  uint32_t GetGroupsMask (void) const;
   34.45 -
   34.46 -  /**
   34.47 -  * \returns an Address instance which represents this
   34.48 -  * NetlinkSocketAddress instance.
   34.49 -  */
   34.50 -  operator Address (void) const;
   34.51 -  /**
   34.52 -  * \param address the Address instance to convert from.
   34.53 -  *
   34.54 -  * Returns an NetlinkSocketAddress which corresponds to the input
   34.55 -  * Address
   34.56 -  */
   34.57 -  static NetlinkSocketAddress ConvertFrom (const Address &address);
   34.58 -  /**
   34.59 -  * \returns true if the address matches, false otherwise.
   34.60 -  */
   34.61 -  static bool IsMatchingType (const Address &address);
   34.62 -private:
   34.63 -  static uint8_t GetType (void);
   34.64 -  Address ConvertTo (void) const;
   34.65 -
   34.66 -  uint32_t m_pid;
   34.67 -  uint32_t m_groups;
   34.68 -
   34.69 -};
   34.70 -
   34.71 -
   34.72 -} // namespace ns3
   34.73 -
   34.74 -#endif /* NETLINK_SOCKET_ADDRESS_H */
    35.1 --- a/model/netlink/netlink-socket-factory.cc	Mon Apr 18 09:01:30 2011 +0200
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,48 +0,0 @@
    35.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    35.5 -/*
    35.6 - * Copyright (c) 2008 Liu Jian
    35.7 - *
    35.8 - * This program is free software; you can redistribute it and/or modify
    35.9 - * it under the terms of the GNU General Public License version 2 as
   35.10 - * published by the Free Software Foundation;
   35.11 - *
   35.12 - * This program is distributed in the hope that it will be useful,
   35.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   35.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   35.15 - * GNU General Public License for more details.
   35.16 - *
   35.17 - * You should have received a copy of the GNU General Public License
   35.18 - * along with this program; if not, write to the Free Software
   35.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   35.20 - *
   35.21 - * Author: Liu Jian <liujatp@gmail.com>
   35.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   35.23 - */
   35.24 -
   35.25 -#include "netlink-socket-factory.h"
   35.26 -#include "netlink-socket.h"
   35.27 -#include "ns3/node.h"
   35.28 -
   35.29 -namespace ns3 {
   35.30 -
   35.31 -NS_OBJECT_ENSURE_REGISTERED (NetlinkSocketFactory);
   35.32 -
   35.33 -TypeId 
   35.34 -NetlinkSocketFactory::GetTypeId (void)
   35.35 -{
   35.36 -  static TypeId tid = TypeId ("ns3::NetlinkSocketFactory")
   35.37 -    .SetParent<SocketFactory> ();
   35.38 -  return tid;
   35.39 -}
   35.40 -
   35.41 -NetlinkSocketFactory::NetlinkSocketFactory ()
   35.42 -{}
   35.43 -
   35.44 -Ptr<Socket> NetlinkSocketFactory::CreateSocket (void)
   35.45 -{
   35.46 -  Ptr<Node> node = GetObject<Node> ();
   35.47 -  Ptr<NetlinkSocket> socket = CreateObject<NetlinkSocket> ();
   35.48 -  socket->SetNode (node);
   35.49 -  return socket;
   35.50 -} 
   35.51 -} // namespace ns3
    36.1 --- a/model/netlink/netlink-socket-factory.h	Mon Apr 18 09:01:30 2011 +0200
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,52 +0,0 @@
    36.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    36.5 -/*
    36.6 - * Copyright (c) 2008 Liu Jian
    36.7 - *
    36.8 - * This program is free software; you can redistribute it and/or modify
    36.9 - * it under the terms of the GNU General Public License version 2 as
   36.10 - * published by the Free Software Foundation;
   36.11 - *
   36.12 - * This program is distributed in the hope that it will be useful,
   36.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   36.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   36.15 - * GNU General Public License for more details.
   36.16 - *
   36.17 - * You should have received a copy of the GNU General Public License
   36.18 - * along with this program; if not, write to the Free Software
   36.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   36.20 - *
   36.21 - * Author: Liu Jian <liujatp@gmail.com>
   36.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   36.23 - */
   36.24 -
   36.25 -#ifndef NETLINK_SOCKET_FACTORY_H
   36.26 -#define NETLINK_SOCKET_FACTORY_H
   36.27 -
   36.28 -#include "ns3/socket-factory.h"
   36.29 -
   36.30 -namespace ns3 {
   36.31 -
   36.32 -class Socket;
   36.33 -
   36.34 -/**
   36.35 - * This can be used as an interface in a node in order for the node to
   36.36 - * generate NetlinkSockets.
   36.37 - */
   36.38 -class NetlinkSocketFactory : public SocketFactory
   36.39 -{
   36.40 -public:
   36.41 -  static TypeId GetTypeId (void);
   36.42 -
   36.43 -  NetlinkSocketFactory ();
   36.44 -
   36.45 -  /**
   36.46 -   * Creates a NetlinkSocket and returns a pointer to it.
   36.47 -   *
   36.48 -   * \return a pointer to the created socket
   36.49 -   */
   36.50 -  virtual Ptr<Socket> CreateSocket (void);
   36.51 -};
   36.52 -
   36.53 -} // namespace ns3
   36.54 -
   36.55 -#endif /* NETLINK_SOCKET_FACTORY_H */
    37.1 --- a/model/netlink/netlink-socket-test.cc	Mon Apr 18 09:01:30 2011 +0200
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,589 +0,0 @@
    37.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    37.5 -/*
    37.6 - * Copyright (c) 2008 Liu Jian
    37.7 - *
    37.8 - * This program is free software; you can redistribute it and/or modify
    37.9 - * it under the terms of the GNU General Public License version 2 as
   37.10 - * published by the Free Software Foundation;
   37.11 - *
   37.12 - * This program is distributed in the hope that it will be useful,
   37.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   37.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   37.15 - * GNU General Public License for more details.
   37.16 - *
   37.17 - * You should have received a copy of the GNU General Public License
   37.18 - * along with this program; if not, write to the Free Software
   37.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   37.20 - *
   37.21 - * Author: Liu Jian <liujatp@gmail.com>
   37.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   37.23 - */
   37.24 -
   37.25 -#include "ns3/test.h"
   37.26 -#include "ns3/simulator.h"
   37.27 -#include "ns3/packet.h"
   37.28 -#include "ns3/node-container.h"
   37.29 -#include "ns3/internet-stack-helper.h"
   37.30 -#include "ns3/point-to-point-helper.h"
   37.31 -#include "ns3/ipv4-address-helper.h"
   37.32 -#include "ns3/ipv4-global-routing-helper.h"
   37.33 -#include "ns3/socket-factory.h"
   37.34 -#include "ns3/string.h"
   37.35 -#include "ns3/assert.h"
   37.36 -#include "ns3/log.h"
   37.37 -#include "ns3/socket.h"
   37.38 -#include "netlink-socket-factory.h"
   37.39 -#include "netlink-message.h"
   37.40 -#include "netlink-socket-address.h"
   37.41 -#include <sys/socket.h>
   37.42 -#include <string>
   37.43 -#include <list>
   37.44 -
   37.45 -
   37.46 -NS_LOG_COMPONENT_DEFINE ("NetlinkSocketTest");
   37.47 -
   37.48 -namespace ns3 {
   37.49 -
   37.50 -
   37.51 -class NetlinkSocketTestCase: public TestCase
   37.52 -{
   37.53 -public:
   37.54 -  NetlinkSocketTestCase ();
   37.55 -  virtual bool DoRun (void);
   37.56 -private:
   37.57 -  NetlinkMessage BuildGetMessage (uint16_t type, uint16_t flags);
   37.58 -  NetlinkMessage BuildAddressMessage (uint16_t type, uint16_t flags);
   37.59 -  NetlinkMessage BuildLinkChangeMessage (uint16_t type, uint16_t flags);
   37.60 -  NetlinkMessage BuildRouteMessage (uint16_t type, uint16_t flags);
   37.61 -  MultipartNetlinkMessage BuildMultipartMessage (uint16_t type, uint16_t flags);
   37.62 -
   37.63 -  bool CheckIsAck (NetlinkMessage nlmsg);
   37.64 -  bool CheckIsDump (MultipartNetlinkMessage nlmsg);
   37.65 -  bool CheckIsEqual (NetlinkMessageHeader nhr1, NetlinkMessageHeader nhr2);
   37.66 -  bool CheckIsEqual (NetlinkMessage nlmsg1, NetlinkMessage nlmsg2);
   37.67 -  bool CheckIsEqual (MultipartNetlinkMessage mulmsg1, MultipartNetlinkMessage mulmsg2);
   37.68 -
   37.69 -  bool TestNetlinkSerilization ();
   37.70 -  bool TestInterfaceAddressMessage ();
   37.71 -  bool TestInferfaceInfoMessage ();
   37.72 -  bool TestRouteMessage ();
   37.73 -  bool TestBroadcastMessage ();
   37.74 -
   37.75 -  void ReceiveUnicastPacket (Ptr<Socket> socket);
   37.76 -  void ReceiveMulticastPacket (Ptr<Socket> socket);
   37.77 -  void SendCmdToKernel (uint16_t type);
   37.78 -  void SendNetlinkMessage (NetlinkMessage nlmsg);
   37.79 -  void MonitorKernelChanges ();
   37.80 -
   37.81 -  std::list<MultipartNetlinkMessage> m_unicastList;
   37.82 -  std::list<MultipartNetlinkMessage> m_multicastList;
   37.83 -  Ptr<Socket> m_cmdSock;
   37.84 -  Ptr<Socket> m_groupSock;  
   37.85 -  int m_pid;
   37.86 -};
   37.87 -
   37.88 -
   37.89 -
   37.90 -NetlinkMessage
   37.91 -NetlinkSocketTestCase::BuildGetMessage (uint16_t type, uint16_t flags)
   37.92 -{
   37.93 -  NS_ASSERT (type == NETLINK_RTM_GETLINK || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETROUTE);
   37.94 -
   37.95 -  NetlinkMessage nlmsg;
   37.96 -  flags |= (NETLINK_MSG_F_DUMP|NETLINK_MSG_F_ACK|NETLINK_MSG_F_REQUEST);
   37.97 -  nlmsg.SetHeader (NetlinkMessageHeader (type, flags, 0, 0));
   37.98 -  GeneralMessage genmsg;
   37.99 -  genmsg.SetFamily (AF_INET);
  37.100 -  nlmsg.SetGeneralMessage (genmsg);
  37.101 -  //no attributes appended
  37.102 -  return nlmsg;
  37.103 -}
  37.104 -
  37.105 -NetlinkMessage
  37.106 -NetlinkSocketTestCase::BuildAddressMessage (uint16_t type, uint16_t flags)
  37.107 -{
  37.108 -  NS_ASSERT (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR);
  37.109 -
  37.110 -  flags |= (NETLINK_MSG_F_ACK|NETLINK_MSG_F_REQUEST); 
  37.111 -  if (type == NETLINK_RTM_NEWADDR)
  37.112 -    {
  37.113 -      flags |= NETLINK_MSG_F_CREATE;
  37.114 -    }
  37.115 -
  37.116 -  NetlinkMessage nlmsg;
  37.117 -  //set header
  37.118 -  nlmsg.SetHeader (NetlinkMessageHeader (type, flags, 0, 0));
  37.119 -
  37.120 -  //set service module
  37.121 -  InterfaceAddressMessage ifamsg;
  37.122 -  ifamsg.SetFamily (AF_INET);
  37.123 -  ifamsg.SetLength (24);
  37.124 -  ifamsg.SetInterfaceIndex (3);
  37.125 -
  37.126 -  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LOCAL, ADDRESS, Ipv4Address("192.168.0.1")));
  37.127 -  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ADDRESS,ADDRESS, Ipv4Address("192.168.0.2")));
  37.128 -  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LABEL, STRING, "TESTSTRING"));
  37.129 -
  37.130 -  nlmsg.SetInterfaceAddressMessage (ifamsg);
  37.131 -  return nlmsg;
  37.132 -}
  37.133 -
  37.134 -NetlinkMessage
  37.135 -NetlinkSocketTestCase::BuildLinkChangeMessage (uint16_t type, uint16_t flags)
  37.136 -{
  37.137 -  NetlinkMessage nlmsg;
  37.138 -  NS_LOG_WARN (this << type << flags << " not supported");
  37.139 -  return nlmsg;
  37.140 -}
  37.141 -
  37.142 -NetlinkMessage
  37.143 -NetlinkSocketTestCase::BuildRouteMessage (uint16_t type, uint16_t flags)
  37.144 -{
  37.145 -  NS_ASSERT (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE);
  37.146 -
  37.147 -  flags |= (NETLINK_MSG_F_ACK|NETLINK_MSG_F_REQUEST); 
  37.148 -  if (type == NETLINK_RTM_NEWROUTE)
  37.149 -    {
  37.150 -      flags |= NETLINK_MSG_F_CREATE;
  37.151 -    }
  37.152 -
  37.153 -  NetlinkMessage nlmsg;
  37.154 -  //set header
  37.155 -  nlmsg.SetHeader (NetlinkMessageHeader (type, flags, 0, m_pid));
  37.156 -
  37.157 -  //set service module
  37.158 -  RouteMessage rtmsg;
  37.159 -  //set attribute
  37.160 -  rtmsg.SetFamily (AF_INET);
  37.161 -  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, Ipv4Address ("192.168.0.10")));
  37.162 -  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, Ipv4Address ("192.168.2.10")));
  37.163 -  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, Ipv4Address ("10.1.1.10")));
  37.164 -  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, (uint32_t)2));
  37.165 -
  37.166 -  nlmsg.SetRouteMessage(rtmsg);
  37.167 -  return nlmsg;
  37.168 -}
  37.169 -
  37.170 -MultipartNetlinkMessage
  37.171 -NetlinkSocketTestCase::BuildMultipartMessage (uint16_t type, uint16_t flags)
  37.172 -{
  37.173 -  //usually multi-part message used for message dump, kernel return to user space for NETLINK_RTM_GETxxx
  37.174 -  //type = NETLINK_RTM_NEWxxx, flags = NETLINK_MSG_F_MULTI, terminated by NETLINK_MSG_DONE, 
  37.175 -  //here this example contain 2 NETLINK_MSG_F_MULTI
  37.176 -  NS_ASSERT (flags&NETLINK_MSG_F_MULTI);
  37.177 -
  37.178 -  MultipartNetlinkMessage nlmsg;
  37.179 -  NetlinkMessage nlmsg1, nlmsg2, nlmsg3;
  37.180 -  nlmsg1 = BuildAddressMessage (NETLINK_RTM_NEWADDR, NETLINK_MSG_F_MULTI);
  37.181 -  nlmsg.AppendMessage (nlmsg1);
  37.182 -  //the first nlmsg
  37.183 -  nlmsg2 = BuildRouteMessage (NETLINK_RTM_NEWROUTE, NETLINK_MSG_F_MULTI);
  37.184 -  nlmsg.AppendMessage (nlmsg2);
  37.185 -  //the second nlmsg
  37.186 -  nlmsg3.SetHeader (NetlinkMessageHeader (NETLINK_MSG_DONE, flags, 1, m_pid));
  37.187 -  nlmsg.AppendMessage (nlmsg3);
  37.188 -
  37.189 -  return nlmsg;
  37.190 -}
  37.191 -
  37.192 -
  37.193 -
  37.194 -
  37.195 -bool
  37.196 -NetlinkSocketTestCase::CheckIsAck (NetlinkMessage nlmsg)
  37.197 -{
  37.198 -  return (nlmsg.GetMsgType () == NETLINK_MSG_ERROR && nlmsg.GetErrorMessage ().GetError () == 0);
  37.199 -}
  37.200 -
  37.201 -bool
  37.202 -NetlinkSocketTestCase::CheckIsDump (MultipartNetlinkMessage mulmsg)
  37.203 -{
  37.204 -  return (mulmsg.GetNMessages () > 0 && mulmsg.GetMessage (0).GetHeader ().GetMsgFlags () & NETLINK_MSG_F_MULTI &&
  37.205 -          mulmsg.GetMessage (mulmsg.GetNMessages () - 1).GetMsgType () == NETLINK_MSG_DONE); 
  37.206 -}
  37.207 -
  37.208 -bool
  37.209 -NetlinkSocketTestCase::CheckIsEqual (NetlinkMessageHeader nhr1, NetlinkMessageHeader nhr2)
  37.210 -{
  37.211 -  return (nhr1.GetMsgType () == nhr2.GetMsgType () && nhr1.GetMsgFlags () == nhr2.GetMsgFlags ()
  37.212 -          && nhr1.GetMsgLen () == nhr2.GetMsgLen ());
  37.213 -}
  37.214 -
  37.215 -bool
  37.216 -NetlinkSocketTestCase::CheckIsEqual (NetlinkMessage nlmsg1, NetlinkMessage nlmsg2)
  37.217 -{
  37.218 -  return CheckIsEqual (nlmsg1.GetHeader (), nlmsg2.GetHeader ());
  37.219 -}
  37.220 -
  37.221 -bool
  37.222 -NetlinkSocketTestCase::CheckIsEqual (MultipartNetlinkMessage mulmsg1, MultipartNetlinkMessage mulmsg2)
  37.223 -{
  37.224 -  if (mulmsg1.GetNMessages () != mulmsg2.GetNMessages ())
  37.225 -    return false;
  37.226 -
  37.227 -  for (uint32_t i = 0; i < mulmsg1.GetNMessages(); i ++)
  37.228 -    {
  37.229 -      if (!CheckIsEqual (mulmsg1.GetMessage (i), mulmsg2.GetMessage (i)))
  37.230 -        {
  37.231 -          return false;
  37.232 -        }
  37.233 -    }
  37.234 -  return true;  
  37.235 -}
  37.236 -
  37.237 -bool
  37.238 -NetlinkSocketTestCase::TestNetlinkSerilization ()
  37.239 -{
  37.240 -  MultipartNetlinkMessage multinlmsg1, multinlmsg2;
  37.241 -  Ptr<Packet> p = Create<Packet> ();
  37.242 -  bool result = true;
  37.243 -
  37.244 -  multinlmsg1 = BuildMultipartMessage (NETLINK_RTM_NEWADDR, NETLINK_MSG_F_REQUEST|NETLINK_MSG_F_MULTI);
  37.245 -  p->AddHeader (multinlmsg1);
  37.246 -  p->RemoveHeader (multinlmsg2);
  37.247 -  NS_TEST_ASSERT_MSG_EQ (CheckIsEqual (multinlmsg1, multinlmsg2), true, "Should be equal");
  37.248 -
  37.249 -  return result;
  37.250 -}
  37.251 -bool
  37.252 -NetlinkSocketTestCase::TestInterfaceAddressMessage ()
  37.253 -{
  37.254 -  MultipartNetlinkMessage dump1, dump2, dump3;
  37.255 -  NetlinkMessage nlmsg1,nlmsg2;
  37.256 -  bool result = true;
  37.257 -
  37.258 -  //dump interface address
  37.259 -  SendNetlinkMessage (BuildGetMessage (NETLINK_RTM_GETADDR, 0));
  37.260 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue should be 1 (RTM_GETADDR)");
  37.261 -  dump1 = m_unicastList.front ();
  37.262 -  m_unicastList.pop_front ();
  37.263 -  NS_TEST_ASSERT_MSG_EQ (CheckIsDump (dump1), true, "Should be dump msg");
  37.264 -
  37.265 -  //add interface address
  37.266 -  // Not implemented yet (100325)
  37.267 -#if 0
  37.268 -  SendNetlinkMessage (BuildAddressMessage (NETLINK_RTM_NEWADDR,0));
  37.269 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue should be 1 (RTM_NEWADDR)");
  37.270 -  nlmsg1 = m_unicastList.front ().GetMessage (0);
  37.271 -  m_unicastList.pop_front ();
  37.272 -  NS_TEST_ASSERT_MSG_EQ (CheckIsAck (nlmsg1), true, "msg should be Ack");
  37.273 -#endif
  37.274 -
  37.275 -  //dump interface address
  37.276 -  SendNetlinkMessage (BuildGetMessage (NETLINK_RTM_GETADDR, 0));
  37.277 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue should be 1 (RTM_GETADDR)");
  37.278 -  dump2 = m_unicastList.front ();
  37.279 -  m_unicastList.pop_front ();
  37.280 -  NS_TEST_ASSERT_MSG_EQ (CheckIsDump (dump2), true, "msg should be dump");
  37.281 -
  37.282 -  //del interface address
  37.283 -  // Not implemented yet (100325)
  37.284 -#if 0
  37.285 -  SendNetlinkMessage (BuildAddressMessage (NETLINK_RTM_DELADDR,0));
  37.286 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_DELADDR)");
  37.287 -  nlmsg2 = m_unicastList.front ().GetMessage (0);
  37.288 -  m_unicastList.pop_front ();
  37.289 -  NS_TEST_ASSERT_MSG_EQ (CheckIsAck (nlmsg2), true, "msg should be Ack");
  37.290 -#endif
  37.291 -
  37.292 -  //dump interface address
  37.293 -  SendNetlinkMessage (BuildGetMessage (NETLINK_RTM_GETADDR, 0));
  37.294 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_GETADDR)");
  37.295 -  dump3 = m_unicastList.front ();
  37.296 -  m_unicastList.pop_front ();
  37.297 -  NS_TEST_ASSERT_MSG_EQ (CheckIsDump (dump3), true, "msg should be dump");
  37.298 -
  37.299 -  NS_TEST_ASSERT_MSG_EQ (CheckIsEqual (dump1, dump3), true, "Dump msg should be same");
  37.300 -
  37.301 -  return result;
  37.302 -}
  37.303 -
  37.304 -
  37.305 -bool
  37.306 -NetlinkSocketTestCase::TestRouteMessage ()
  37.307 -{
  37.308 -  MultipartNetlinkMessage dump1, dump2, dump3;
  37.309 -  NetlinkMessage nlmsg1,nlmsg2;
  37.310 -  bool result = true;
  37.311 -
  37.312 -  //dump route entry
  37.313 -  SendNetlinkMessage (BuildGetMessage (NETLINK_RTM_GETROUTE, 0));
  37.314 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_GETROUTE)");
  37.315 -  dump1 = m_unicastList.front ();
  37.316 -  m_unicastList.pop_front ();
  37.317 -  NS_TEST_ASSERT_MSG_EQ (CheckIsDump (dump1), true, "msg should be dump");
  37.318 -
  37.319 -  //add route entry
  37.320 -  SendNetlinkMessage (BuildRouteMessage (NETLINK_RTM_NEWROUTE,0));
  37.321 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_NEWROUTE)");
  37.322 -  nlmsg1 = m_unicastList.front ().GetMessage (0);
  37.323 -  m_unicastList.pop_front ();
  37.324 -  NS_TEST_ASSERT_MSG_EQ (CheckIsAck (nlmsg1), true, "msg should be Ack");
  37.325 -
  37.326 -  //dump route entry
  37.327 -  SendNetlinkMessage (BuildGetMessage (NETLINK_RTM_GETROUTE, 0));
  37.328 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_GETROUTE)");
  37.329 -  dump2 = m_unicastList.front ();
  37.330 -  m_unicastList.pop_front ();
  37.331 -  NS_TEST_ASSERT_MSG_EQ (CheckIsDump (dump2), true, "msg should be dump");
  37.332 -
  37.333 -  //del route entry
  37.334 -  SendNetlinkMessage (BuildRouteMessage (NETLINK_RTM_DELROUTE, 0));
  37.335 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_DELROUTE)");
  37.336 -  nlmsg2 = m_unicastList.front ().GetMessage (0);
  37.337 -  m_unicastList.pop_front ();
  37.338 -  NS_TEST_ASSERT_MSG_EQ (CheckIsAck (nlmsg2), true, "msg should be Ack");
  37.339 -
  37.340 -  //dump route entry
  37.341 -  SendNetlinkMessage (BuildGetMessage (NETLINK_RTM_GETROUTE, 0));
  37.342 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_GETROUTE)");
  37.343 -  dump3 = m_unicastList.front ();
  37.344 -  m_unicastList.pop_front ();
  37.345 -  NS_TEST_ASSERT_MSG_EQ (CheckIsDump (dump3), true, "msg should be dump");
  37.346 -
  37.347 -  NS_TEST_ASSERT_MSG_EQ (CheckIsEqual (dump1, dump3), true, "msg should be same");
  37.348 -
  37.349 -  return result;
  37.350 -}
  37.351 -
  37.352 -bool
  37.353 -NetlinkSocketTestCase::TestInferfaceInfoMessage ()
  37.354 -{
  37.355 -  //now netlink not support NEWLINK/DELLINK yet
  37.356 -  MultipartNetlinkMessage multinlmsg;
  37.357 -  bool result = true;
  37.358 -
  37.359 -  //dump interface address
  37.360 -  SendNetlinkMessage (BuildGetMessage (NETLINK_RTM_GETLINK, 0));
  37.361 -  NS_TEST_ASSERT_MSG_EQ (m_unicastList.size (), 1, "queue size should be 1 (RTM_GETLINK)");
  37.362 -  multinlmsg = m_unicastList.front ();
  37.363 -  m_unicastList.pop_front ();
  37.364 -  NS_TEST_ASSERT_MSG_EQ (CheckIsDump (multinlmsg), true, "msg should be dump");
  37.365 -
  37.366 -  NS_TEST_ASSERT_MSG_EQ ((multinlmsg.GetNMessages () > 1) && (multinlmsg.GetMessage (0).GetMsgType () == NETLINK_RTM_NEWLINK),
  37.367 -                        true, "msg might be incorrect");
  37.368 -
  37.369 -  return result;
  37.370 -}
  37.371 -
  37.372 -bool
  37.373 -NetlinkSocketTestCase::TestBroadcastMessage ()
  37.374 -{
  37.375 -  bool result = true;
  37.376 -  //at 2Xs, m_cmdSock send an request to kernel to add/del an interface address
  37.377 -  //and an route entry,  the m_groupSock will recv the changed information
  37.378 -  //through the broadcast way  
  37.379 -  m_multicastList.clear();
  37.380 -  Simulator::Schedule (Seconds (1), &NetlinkSocketTestCase::MonitorKernelChanges, this);
  37.381 -  // Not implemented yet (100325)
  37.382 -#if 0
  37.383 -  Simulator::Schedule (Seconds (2), &NetlinkSocketTestCase::SendCmdToKernel, this, NETLINK_RTM_NEWADDR);
  37.384 -#endif
  37.385 -  Simulator::Schedule (Seconds (4), &NetlinkSocketTestCase::SendCmdToKernel, this, NETLINK_RTM_NEWROUTE);
  37.386 -  // Not implemented yet (100325)
  37.387 -#if 0
  37.388 -  Simulator::Schedule (Seconds (6), &NetlinkSocketTestCase::SendCmdToKernel, this, NETLINK_RTM_DELADDR);
  37.389 -#endif
  37.390 -  Simulator::Schedule (Seconds (8), &NetlinkSocketTestCase::SendCmdToKernel, this, NETLINK_RTM_DELROUTE);
  37.391 -
  37.392 -  return result;
  37.393 -};
  37.394 -
  37.395 -
  37.396 -void
  37.397 -NetlinkSocketTestCase::SendNetlinkMessage (NetlinkMessage nlmsg)
  37.398 -{
  37.399 -#if 1
  37.400 -  Ptr<Packet> p = Create<Packet> ();
  37.401 -  p->AddHeader (MultipartNetlinkMessage (nlmsg));