make it somewhat build sanely
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 05 May 2011 09:28:21 +0200
changeset 662fe1f3e576c9
parent 65 227f6347e4e1
child 67 fb900a594421
make it somewhat build sanely
.hgignore
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/ns3-socket-fd-factory.cc
model/ns3-socket-fd-factory.h
netlink/netlink-attribute.cc
netlink/netlink-attribute.h
netlink/netlink-message-route.cc
netlink/netlink-message-route.h
netlink/netlink-message.cc
netlink/netlink-message.h
netlink/netlink-socket-address.cc
netlink/netlink-socket-address.h
netlink/netlink-socket-factory.cc
netlink/netlink-socket-factory.h
netlink/netlink-socket.cc
netlink/netlink-socket.h
ns3waf/__init__.py
ns3waf/__init__.pyc
test/netlink-socket-test.cc
waf
wscript
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Thu May 05 09:28:21 2011 +0200
     1.3 @@ -0,0 +1,10 @@
     1.4 +\.rej$
     1.5 +\.orig$
     1.6 +\.o$
     1.7 +~$
     1.8 +^build
     1.9 +^objdir
    1.10 +^elf-cache
    1.11 +^files-
    1.12 +^.waf-
    1.13 +^.lock-
     2.1 --- a/model/netlink-attribute.cc	Tue Apr 19 23:13:50 2011 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,433 +0,0 @@
     2.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2.5 -/*
     2.6 - * Copyright (c) 2008 Liu Jian
     2.7 - *
     2.8 - * This program is free software; you can redistribute it and/or modify
     2.9 - * it under the terms of the GNU General Public License version 2 as
    2.10 - * published by the Free Software Foundation;
    2.11 - *
    2.12 - * This program is distributed in the hope that it will be useful,
    2.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 - * GNU General Public License for more details.
    2.16 - *
    2.17 - * You should have received a copy of the GNU General Public License
    2.18 - * along with this program; if not, write to the Free Software
    2.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.20 - *
    2.21 - * Author: Liu Jian <liujatp@gmail.com>
    2.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    2.23 - */
    2.24 -
    2.25 -#include "netlink-attribute.h"
    2.26 -#include "netlink-message.h"
    2.27 -#include "netlink-message-route.h"
    2.28 -#include "ns3/address-utils.h"
    2.29 -
    2.30 -namespace ns3 {
    2.31 -
    2.32 -
    2.33 -/***********************************************************************************
    2.34 -* \ NetlinkAttributeValue
    2.35 -***********************************************************************************/
    2.36 -NetlinkAttributeValue::NetlinkAttributeValue ()
    2.37 -{
    2.38 -  m_type = UNSPEC;
    2.39 -  m_u32 = 0;
    2.40 -}
    2.41 -
    2.42 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v)
    2.43 -{
    2.44 -  NS_ASSERT (type == U8);
    2.45 -  m_type = U8;
    2.46 -  m_u8 = v;
    2.47 -}
    2.48 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v)
    2.49 -{
    2.50 -  NS_ASSERT (type == U16);
    2.51 -  m_type = U16;
    2.52 -  m_u16 = v;
    2.53 -}
    2.54 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v)
    2.55 -{
    2.56 -  NS_ASSERT (type == U32);
    2.57 -  m_type = U32;
    2.58 -  m_u32 = v;
    2.59 -}
    2.60 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v)
    2.61 -{
    2.62 -  NS_ASSERT (type == U64);
    2.63 -  m_type = U64;
    2.64 -  m_u64 = v;
    2.65 -}
    2.66 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v)
    2.67 -{
    2.68 -  NS_ASSERT (type == STRING);
    2.69 -  m_type = STRING;
    2.70 -  m_string = v;
    2.71 -}
    2.72 -NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, Address v)
    2.73 -{
    2.74 -  NS_ASSERT (type == ADDRESS);
    2.75 -  m_type = ADDRESS;
    2.76 -  m_address = v;
    2.77 -}
    2.78 -
    2.79 -void
    2.80 -NetlinkAttributeValue::SetType (NetlinkAttributeValueType type)
    2.81 -{
    2.82 -  m_type = type;
    2.83 -}
    2.84 -NetlinkAttributeValueType
    2.85 -NetlinkAttributeValue::GetType (void) const
    2.86 -{
    2.87 -  return m_type;
    2.88 -}
    2.89 -void
    2.90 -NetlinkAttributeValue::SetAddress (Address value)
    2.91 -{
    2.92 -  m_address = value;
    2.93 -}
    2.94 -void
    2.95 -NetlinkAttributeValue::SetString (std::string value)
    2.96 -{
    2.97 -  m_string = value;
    2.98 -}
    2.99 -void
   2.100 -NetlinkAttributeValue::SetU64 (uint64_t value)
   2.101 -{
   2.102 -  m_u64 = value;
   2.103 -}
   2.104 -void
   2.105 -NetlinkAttributeValue::SetU32 (uint32_t value)
   2.106 -{
   2.107 -  m_u32 = value;
   2.108 -}
   2.109 -void
   2.110 -NetlinkAttributeValue::SetU16 (uint16_t value)
   2.111 -{
   2.112 -  m_u16 = value;
   2.113 -}
   2.114 -void
   2.115 -NetlinkAttributeValue::SetU8 (uint8_t value)
   2.116 -{
   2.117 -  m_u8 = value;
   2.118 -}
   2.119 -Address
   2.120 -NetlinkAttributeValue::GetAddress (void) const
   2.121 -{
   2.122 -  return m_address;
   2.123 -}
   2.124 -std::string
   2.125 -NetlinkAttributeValue::GetString (void) const
   2.126 -{
   2.127 -  return m_string;
   2.128 -}
   2.129 -uint64_t
   2.130 -NetlinkAttributeValue::GetU64 (void) const
   2.131 -{
   2.132 -  return m_u64;
   2.133 -}
   2.134 -uint32_t
   2.135 -NetlinkAttributeValue::GetU32 (void) const
   2.136 -{
   2.137 -  return m_u32;
   2.138 -}
   2.139 -uint16_t
   2.140 -NetlinkAttributeValue::GetU16 (void) const
   2.141 -{
   2.142 -  return m_u16;
   2.143 -}
   2.144 -uint8_t
   2.145 -NetlinkAttributeValue::GetU8 (void) const
   2.146 -{
   2.147 -  return m_u8;
   2.148 -}
   2.149 -
   2.150 -void
   2.151 -NetlinkAttributeValue::Serialize (Buffer::Iterator& start) const
   2.152 -{
   2.153 -  uint32_t len;
   2.154 -
   2.155 -  if (m_type == U8)
   2.156 -    {
   2.157 -      start.WriteU8 (m_u8);
   2.158 -      len = 1;
   2.159 -    }
   2.160 -  else if(m_type == U16)
   2.161 -    {
   2.162 -      start.WriteU16 (m_u16);
   2.163 -      len = 2;
   2.164 -    }
   2.165 -  else if(m_type == U32)
   2.166 -    {
   2.167 -      start.WriteU32 (m_u32);
   2.168 -      len = 4;
   2.169 -    }
   2.170 -  else if(m_type == STRING)
   2.171 -    {
   2.172 -      start.Write ((const uint8_t *)m_string.c_str (), (uint32_t)m_string.size ()+1);
   2.173 -      len = (uint32_t)m_string.size () + 1;
   2.174 -    }
   2.175 -  else if(m_type == ADDRESS)
   2.176 -    {
   2.177 -      WriteTo (start, m_address);
   2.178 -      len = m_address.GetLength ();
   2.179 -    }
   2.180 -  else
   2.181 -    {
   2.182 -      len = 0;
   2.183 -    }
   2.184 -  //netlink align
   2.185 -  start.WriteU8 (0, NETLINK_MSG_ALIGN (len) - len);
   2.186 -}
   2.187 -
   2.188 -uint32_t
   2.189 -NetlinkAttributeValue::DeserializeWithType (Buffer::Iterator& start, 
   2.190 -                                            NetlinkAttributeValueType_e type, uint16_t remaining)
   2.191 -{
   2.192 -  uint32_t len =0;
   2.193 -  m_type = type;  
   2.194 -
   2.195 -  if (m_type == U8)
   2.196 -    {
   2.197 -      m_u8 = start.ReadU8 ();
   2.198 -      len = 1;
   2.199 -    }
   2.200 -  else if (m_type == U16)
   2.201 -    {
   2.202 -      m_u16 = start.ReadU16 ();
   2.203 -      len = 2;
   2.204 -    }
   2.205 -  else if (m_type == U32)
   2.206 -    {
   2.207 -      m_u32 = start.ReadU32 ();
   2.208 -      len = 4;
   2.209 -    }
   2.210 -  else if (m_type == U64)
   2.211 -    {
   2.212 -      m_u64 = start.ReadU64 ();
   2.213 -    }  
   2.214 -  else if (m_type == STRING)
   2.215 -    {
   2.216 -      char buf[512];
   2.217 -      uint32_t i = 0;
   2.218 -      do 
   2.219 -      {
   2.220 -        buf[i] = start.ReadU8 ();
   2.221 -      } while (buf[i++]);
   2.222 -      
   2.223 -      m_string = std::string (buf);
   2.224 -      len = (uint32_t)m_string.size () + 1;
   2.225 -    }
   2.226 -  else if (m_type == ADDRESS)
   2.227 -    {
   2.228 -      ReadFrom (start, m_address, remaining);
   2.229 -      len = m_address.GetLength ();
   2.230 -    }
   2.231 -  else
   2.232 -    {
   2.233 -      len = 0;
   2.234 -    }
   2.235 -
   2.236 -  //netlink align
   2.237 -  uint8_t buf[4];
   2.238 -  start.Read (buf, NETLINK_MSG_ALIGN (len) - len);
   2.239 -  
   2.240 -  return NETLINK_MSG_ALIGN (len);
   2.241 -}
   2.242 -
   2.243 -uint32_t
   2.244 -NetlinkAttributeValue::GetSerializedSize ()const
   2.245 -{
   2.246 -  return NETLINK_MSG_ALIGN (GetSize ());
   2.247 -}
   2.248 -
   2.249 -uint32_t
   2.250 -NetlinkAttributeValue::GetSize () const
   2.251 -{
   2.252 -  uint32_t len;
   2.253 -
   2.254 -  if (m_type == U8)
   2.255 -    {
   2.256 -      len = 1;
   2.257 -    }
   2.258 -  else if(m_type == U16)
   2.259 -    {
   2.260 -      len =  2;
   2.261 -    }
   2.262 -  else if(m_type == U32)
   2.263 -    {
   2.264 -      len =  4;
   2.265 -    }
   2.266 -  else if (m_type == STRING)
   2.267 -    {
   2.268 -      len =  uint32_t (m_string.size () + 1);
   2.269 -    }
   2.270 -  else if (m_type == ADDRESS)
   2.271 -    {
   2.272 -      len =  m_address.GetLength ();
   2.273 -    }
   2.274 -  else
   2.275 -    {
   2.276 -      len = 0;
   2.277 -    }
   2.278 -
   2.279 -    return len;
   2.280 -}
   2.281 -
   2.282 -void
   2.283 -NetlinkAttributeValue::Print (std::ostream &os) const
   2.284 -{
   2.285 -  os << "NetlinkAttributeValue (type= " << m_type <<", v= ";
   2.286 -  if (m_type == U8)
   2.287 -    {
   2.288 -      os << m_u8;
   2.289 -    }
   2.290 -  else if (m_type == U16)
   2.291 -    {
   2.292 -      os << m_u16;
   2.293 -    }
   2.294 -  else if (m_type == U32)
   2.295 -    {
   2.296 -      os << m_u32;
   2.297 -    }
   2.298 -  else if (m_type == U64)
   2.299 -    {
   2.300 -      os << m_u64;
   2.301 -    }  
   2.302 -  else if (m_type == STRING)
   2.303 -    {
   2.304 -      os << m_string;
   2.305 -    }
   2.306 -  else if (m_type == ADDRESS)
   2.307 -    {
   2.308 -      os << "address(" << m_address <<")";
   2.309 -    }
   2.310 -  else
   2.311 -    {
   2.312 -      os << "NULL";
   2.313 -    }
   2.314 -  os <<")";
   2.315 -}
   2.316 -
   2.317 -
   2.318 -/***********************************************************************************
   2.319 -* \ NetlinkAttribute
   2.320 -***********************************************************************************/
   2.321 -
   2.322 -NetlinkAttribute::NetlinkAttribute ()
   2.323 -  : m_len(4),
   2.324 -    m_type (0)
   2.325 -{
   2.326 -}
   2.327 -
   2.328 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload)
   2.329 -{
   2.330 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
   2.331 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
   2.332 -  m_type = type;
   2.333 -}
   2.334 -
   2.335 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload)
   2.336 -{
   2.337 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
   2.338 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
   2.339 -  m_type = type;
   2.340 -}
   2.341 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload)
   2.342 -{
   2.343 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
   2.344 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
   2.345 -  m_type = type;;
   2.346 -}
   2.347 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload)
   2.348 -{
   2.349 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
   2.350 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
   2.351 -  m_type = type;
   2.352 -}
   2.353 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload)
   2.354 -{
   2.355 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
   2.356 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
   2.357 -  m_type = type;
   2.358 -}
   2.359 -NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload)
   2.360 -{
   2.361 -  m_payload = NetlinkAttributeValue (payloadtype, payload);
   2.362 -  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
   2.363 -  m_type = type;
   2.364 -}
   2.365 -
   2.366 -void
   2.367 -NetlinkAttribute::SetAttrLen (uint16_t v)
   2.368 -{
   2.369 -  m_len = v;
   2.370 -}
   2.371 -void 
   2.372 -NetlinkAttribute::SetAttrType (uint16_t v)
   2.373 -{
   2.374 -  m_type = v;
   2.375 -}
   2.376 -void
   2.377 -NetlinkAttribute::SetAttrPayload (NetlinkAttributeValue v)
   2.378 -{
   2.379 -  m_payload = v;
   2.380 -}
   2.381 -uint16_t
   2.382 -NetlinkAttribute::GetAttrLen () const
   2.383 -{
   2.384 -  return m_len;
   2.385 -}
   2.386 -uint16_t
   2.387 -NetlinkAttribute::GetAttrType () const
   2.388 -{
   2.389 -  return m_type;
   2.390 -}
   2.391 -NetlinkAttributeValue
   2.392 -NetlinkAttribute::GetAttrPayload() const
   2.393 -{
   2.394 -  return m_payload;
   2.395 -}
   2.396 -
   2.397 -void 
   2.398 -NetlinkAttribute::Print (std::ostream &os) const
   2.399 -{  
   2.400 -  os << "NetlinkAttribute "
   2.401 -     << "len: " << m_len << " "
   2.402 -     << "type: " << m_type<<" "
   2.403 -     << "payload:[";
   2.404 -  m_payload.Print(os);
   2.405 -  os<<"]";
   2.406 -}
   2.407 -
   2.408 -uint32_t 
   2.409 -NetlinkAttribute::GetSerializedSize (void) const
   2.410 -{
   2.411 -  /* this is the size of an nlattr payload. */
   2.412 -  return NETLINK_MSG_ATTR_SIZE + m_payload.GetSerializedSize ();
   2.413 -}
   2.414 -
   2.415 -void
   2.416 -NetlinkAttribute::Serialize (Buffer::Iterator& start) const
   2.417 -{
   2.418 -  start.WriteU16 (m_len);
   2.419 -  start.WriteU16 (m_type);
   2.420 -  m_payload.Serialize (start);
   2.421 -}
   2.422 -
   2.423 -uint32_t
   2.424 -NetlinkAttribute::Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[])
   2.425 -{
   2.426 -  NetlinkAttributeValueType type;
   2.427 -
   2.428 -  m_len = start.ReadU16 ();
   2.429 -  m_type = start.ReadU16 ();
   2.430 -  type = vtypes[m_type];
   2.431 -  m_payload.DeserializeWithType (start, type, m_len - 4);
   2.432 -
   2.433 -  return GetSerializedSize ();
   2.434 -}
   2.435 -
   2.436 -}; // namespace ns3
     3.1 --- a/model/netlink-attribute.h	Tue Apr 19 23:13:50 2011 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,124 +0,0 @@
     3.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     3.5 -/*
     3.6 - * Copyright (c) 2008 Liu Jian
     3.7 - *
     3.8 - * This program is free software; you can redistribute it and/or modify
     3.9 - * it under the terms of the GNU General Public License version 2 as
    3.10 - * published by the Free Software Foundation;
    3.11 - *
    3.12 - * This program is distributed in the hope that it will be useful,
    3.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 - * GNU General Public License for more details.
    3.16 - *
    3.17 - * You should have received a copy of the GNU General Public License
    3.18 - * along with this program; if not, write to the Free Software
    3.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.20 - *
    3.21 - * Author: Liu Jian <liujatp@gmail.com>
    3.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    3.23 - */
    3.24 -
    3.25 -#ifndef NETLINK_ATTRIBUTE_H
    3.26 -#define NETLINK_ATTRIBUTE_H
    3.27 -
    3.28 -
    3.29 -#include <stdint.h>
    3.30 -#include <string>
    3.31 -#include <ostream>
    3.32 -#include "ns3/address.h"
    3.33 -#include "ns3/buffer.h"
    3.34 -
    3.35 -namespace ns3 {
    3.36 -
    3.37 -/**
    3.38 -* \brief The Netlink Attribute
    3.39 -*/
    3.40 -
    3.41 -typedef enum NetlinkAttributeValueType_e {
    3.42 -  UNSPEC, // invalid initial value.
    3.43 -  U8,
    3.44 -  U16,
    3.45 -  U32,
    3.46 -  U64,
    3.47 -  STRING,
    3.48 -  ADDRESS,
    3.49 -}NetlinkAttributeValueType;
    3.50 -
    3.51 -class NetlinkAttributeValue
    3.52 -{
    3.53 -public:
    3.54 -  NetlinkAttributeValue ();
    3.55 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v);
    3.56 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v);
    3.57 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v);
    3.58 -  NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v);
    3.59 -  NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v);
    3.60 -  NetlinkAttributeValue (NetlinkAttributeValueType type, Address v);
    3.61 -  
    3.62 -  void Serialize (Buffer::Iterator& start) const;
    3.63 -  uint32_t DeserializeWithType (Buffer::Iterator& start, NetlinkAttributeValueType type, uint16_t remaining);
    3.64 -  uint32_t GetSerializedSize (void) const;
    3.65 -  uint32_t GetSize (void) const;
    3.66 -  void Print (std::ostream &os) const;
    3.67 -
    3.68 -  void SetType (NetlinkAttributeValueType type);
    3.69 -  NetlinkAttributeValueType GetType (void) const;
    3.70 -  void SetAddress (Address value);
    3.71 -  void SetString (std::string value);
    3.72 -  void SetU64 (uint64_t value);
    3.73 -  void SetU32 (uint32_t value);
    3.74 -  void SetU16 (uint16_t value);
    3.75 -  void SetU8 (uint8_t value);
    3.76 -  Address GetAddress (void) const;
    3.77 -  std::string GetString (void) const;
    3.78 -  uint64_t GetU64 (void) const;
    3.79 -  uint32_t GetU32 (void) const;
    3.80 -  uint16_t GetU16 (void) const;
    3.81 -  uint8_t GetU8 (void) const;
    3.82 -
    3.83 -private:
    3.84 -  NetlinkAttributeValueType m_type;
    3.85 -  uint64_t m_u64;
    3.86 -  uint32_t m_u32;
    3.87 -  uint16_t m_u16;
    3.88 -  uint8_t m_u8;
    3.89 -  std::string m_string;
    3.90 -  Address m_address;
    3.91 -};
    3.92 -
    3.93 -struct NetlinkAttribute
    3.94 -{
    3.95 -public:
    3.96 -  NetlinkAttribute ();
    3.97 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload);
    3.98 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload);
    3.99 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload);
   3.100 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload);
   3.101 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload);
   3.102 -  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload);
   3.103 -
   3.104 -  //static TypeId GetTypeId (void);
   3.105 -  //virtual TypeId GetInstanceTypeId (void) const;
   3.106 -  void Print (std::ostream &os) const;
   3.107 -  uint32_t GetSerializedSize (void) const;
   3.108 -  void Serialize (Buffer::Iterator& start) const;
   3.109 -  uint32_t Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[]);
   3.110 -
   3.111 -  void SetAttrLen (uint16_t v);
   3.112 -  void SetAttrType (uint16_t v);
   3.113 -  void SetAttrPayload (NetlinkAttributeValue v);
   3.114 -  uint16_t GetAttrLen () const;
   3.115 -  uint16_t GetAttrType () const;
   3.116 -  NetlinkAttributeValue GetAttrPayload () const;
   3.117 -
   3.118 -private:
   3.119 -  static const int NETLINK_MSG_ATTR_SIZE = 4; /* size of the nlattr field*/
   3.120 -  uint16_t m_len;
   3.121 -  uint16_t m_type; 
   3.122 -  NetlinkAttributeValue m_payload;
   3.123 -};
   3.124 -
   3.125 -}; // namespace ns3
   3.126 -
   3.127 -#endif /* NETLINK_ATTRIBUTE_H */
     4.1 --- a/model/netlink-message-route.cc	Tue Apr 19 23:13:50 2011 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,647 +0,0 @@
     4.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     4.5 -/*
     4.6 - * Copyright (c) 2008 Liu Jian
     4.7 - *
     4.8 - * This program is free software; you can redistribute it and/or modify
     4.9 - * it under the terms of the GNU General Public License version 2 as
    4.10 - * published by the Free Software Foundation;
    4.11 - *
    4.12 - * This program is distributed in the hope that it will be useful,
    4.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 - * GNU General Public License for more details.
    4.16 - *
    4.17 - * You should have received a copy of the GNU General Public License
    4.18 - * along with this program; if not, write to the Free Software
    4.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.20 - *
    4.21 - * Author: Liu Jian <liujatp@gmail.com>
    4.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    4.23 - */
    4.24 -
    4.25 -#include "netlink-message-route.h"
    4.26 -#include "netlink-message.h"
    4.27 -
    4.28 -namespace ns3 {
    4.29 -
    4.30 -/***********************************************************************************
    4.31 -* \ NetlinkPayload
    4.32 -***********************************************************************************/
    4.33 -TypeId 
    4.34 -NetlinkPayload::GetTypeId (void)
    4.35 -{
    4.36 -  static TypeId tid = TypeId ("ns3::NetlinkPayload")
    4.37 -    .SetParent<ObjectBase> ()
    4.38 -    ;
    4.39 -  return tid;
    4.40 -}
    4.41 -
    4.42 -
    4.43 -/***********************************************************************************
    4.44 -* \ GeneralMessage
    4.45 -***********************************************************************************/
    4.46 -
    4.47 -NS_OBJECT_ENSURE_REGISTERED (GeneralMessage);
    4.48 -NS_OBJECT_ENSURE_REGISTERED (InterfaceInfoMessage);
    4.49 -NS_OBJECT_ENSURE_REGISTERED (InterfaceAddressMessage);
    4.50 -NS_OBJECT_ENSURE_REGISTERED (RouteMessage);
    4.51 -
    4.52 -GeneralMessage::GeneralMessage ()
    4.53 -  : m_family(0)
    4.54 -{}
    4.55 -GeneralMessage::~GeneralMessage ()
    4.56 -{}
    4.57 -
    4.58 -void
    4.59 -GeneralMessage::SetFamily (uint8_t v)
    4.60 -{
    4.61 -  m_family = v;
    4.62 -}
    4.63 -uint8_t
    4.64 -GeneralMessage::GetFamily (void) const
    4.65 -{
    4.66 -  return m_family;
    4.67 -}
    4.68 -
    4.69 -TypeId 
    4.70 -GeneralMessage::GetTypeId (void)
    4.71 -{
    4.72 -  static TypeId tid = TypeId ("ns3::GeneralMessage")
    4.73 -    .SetParent<NetlinkPayload> ()
    4.74 -    .AddConstructor<GeneralMessage> ()
    4.75 -    ;
    4.76 -  return tid;
    4.77 -}
    4.78 -
    4.79 -TypeId 
    4.80 -GeneralMessage::GetInstanceTypeId (void) const
    4.81 -{
    4.82 -  return GetTypeId ();
    4.83 -}
    4.84 -void 
    4.85 -GeneralMessage::Print (std::ostream &os) const
    4.86 -{
    4.87 -  os << " ----GeneralMessage ("
    4.88 -     << "family: " << (uint32_t)m_family << ")"; 
    4.89 -}
    4.90 -
    4.91 -uint32_t 
    4.92 -GeneralMessage::GetSerializedSize (void) const
    4.93 -{
    4.94 -  /* this is the size of an nlmsghdr payload. */
    4.95 -  return NETLINK_MSG_ALIGN (NETLINK_GENMSG_SIZE);
    4.96 -}
    4.97 -
    4.98 -
    4.99 -void
   4.100 -GeneralMessage::Serialize (Buffer::Iterator& start) const
   4.101 -{
   4.102 -  start.WriteU8 (m_family);
   4.103 -  start.WriteU8 (0, 3);
   4.104 -}
   4.105 -
   4.106 -uint32_t
   4.107 -GeneralMessage::Deserialize (Buffer::Iterator& start)
   4.108 -{
   4.109 -  uint8_t buf[3];
   4.110 -  m_family = start.ReadU8 ();
   4.111 -  start.Read (buf, 3);
   4.112 -  return GetSerializedSize ();
   4.113 -}
   4.114 -uint32_t
   4.115 -GeneralMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
   4.116 -{
   4.117 -  uint8_t buf[3];
   4.118 -  m_family = start.ReadU8 ();
   4.119 -  start.Read (buf, 3);
   4.120 -  return GetSerializedSize ();
   4.121 -}
   4.122 -
   4.123 -
   4.124 -uint32_t
   4.125 -GeneralMessage::GetNNetlinkAttribute (void)const
   4.126 -{
   4.127 -  return m_attributes.size ();
   4.128 -}
   4.129 -NetlinkAttribute
   4.130 -GeneralMessage::GetNetlinkAttribute (uint32_t index)const
   4.131 -{
   4.132 -  NS_ASSERT(index < GetNNetlinkAttribute ());
   4.133 -  return m_attributes[index];
   4.134 -}
   4.135 -
   4.136 -uint32_t
   4.137 -GeneralMessage::GetAttributeSerializedSize (void) const
   4.138 -{
   4.139 -  uint32_t size = 0;
   4.140 -
   4.141 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
   4.142 -    {
   4.143 -      size += m_attributes[i].GetSerializedSize ();
   4.144 -    }
   4.145 -  return size;
   4.146 -}
   4.147 -bool
   4.148 -GeneralMessage::GetAttributeByType (NetlinkAttribute& attr, uint16_t type)
   4.149 -{
   4.150 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
   4.151 -    {
   4.152 -      if (type == m_attributes[i].GetAttrType ())
   4.153 -        {
   4.154 -          attr = m_attributes[i];
   4.155 -          return true;
   4.156 -        }
   4.157 -    }
   4.158 -  return false;  
   4.159 -}
   4.160 -void
   4.161 -GeneralMessage::AppendAttribute (NetlinkAttribute v)
   4.162 -{
   4.163 -  m_attributes.push_back (v);
   4.164 -}
   4.165 -
   4.166 -void
   4.167 -GeneralMessage::SerializeAttribute (Buffer::Iterator& start) const
   4.168 -{
   4.169 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
   4.170 -    {
   4.171 -      m_attributes[i].Serialize (start);
   4.172 -    }
   4.173 -}
   4.174 -
   4.175 -void
   4.176 -GeneralMessage::PrintAttribute (std::ostream &os) const
   4.177 -{
   4.178 -  for (uint32_t i = 0; i < m_attributes.size (); i ++)
   4.179 -    {
   4.180 -      os << " ----Attribute (" << i << "):";
   4.181 -      m_attributes[i].Print(os);
   4.182 -    }
   4.183 -}
   4.184 -
   4.185 -/***********************************************************************************
   4.186 -* \ InterfaceInfoMessage
   4.187 -***********************************************************************************/
   4.188 -InterfaceInfoMessage::InterfaceInfoMessage ()
   4.189 -  : m_reserved (0),
   4.190 -    m_deviceType (0),
   4.191 -    m_interfaceIndex(0),
   4.192 -    m_deviceFlags (0),
   4.193 -    m_changeMask (0)
   4.194 -{
   4.195 -  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
   4.196 -  m_attributeTypes[IFL_A_UNSPEC] = UNSPEC;
   4.197 -  m_attributeTypes[IFL_A_ADDRESS] = ADDRESS;
   4.198 -  m_attributeTypes[IFL_A_BROADCAST] = ADDRESS;
   4.199 -  m_attributeTypes[IFL_A_IFNAME] = STRING;
   4.200 -  m_attributeTypes[IFL_A_MTU] = U32;
   4.201 -  m_attributeTypes[IFL_A_LINK] = U32;
   4.202 -  m_attributeTypes[IFL_A_QDISC] = U8;
   4.203 -  m_attributeTypes[IFL_A_STATS] = UNSPEC;
   4.204 -  m_attributeTypes[IFL_A_COST] = UNSPEC;
   4.205 -}
   4.206 -InterfaceInfoMessage::~InterfaceInfoMessage ()
   4.207 -{}
   4.208 -void
   4.209 -InterfaceInfoMessage::SetDeviceType (uint16_t type)
   4.210 -{
   4.211 -  m_deviceType = type;
   4.212 -}
   4.213 -void
   4.214 -InterfaceInfoMessage::SetInterfaceIndex (int32_t index)
   4.215 -{
   4.216 -  m_interfaceIndex = index;
   4.217 -}
   4.218 -void
   4.219 -InterfaceInfoMessage::SetDeviceFlags (uint32_t flags)
   4.220 -{
   4.221 -  m_deviceFlags = flags;
   4.222 -}
   4.223 -void
   4.224 -InterfaceInfoMessage::SetChangeMask (uint32_t mask)
   4.225 -{
   4.226 -  m_changeMask = mask;
   4.227 -}
   4.228 -uint16_t
   4.229 -InterfaceInfoMessage::GetDeviceType (void) const
   4.230 -{
   4.231 -  return m_deviceType;
   4.232 -}
   4.233 -int32_t
   4.234 -InterfaceInfoMessage::GetInterfaceIndex (void) const
   4.235 -{
   4.236 -  return m_interfaceIndex;
   4.237 -}
   4.238 -uint32_t
   4.239 -InterfaceInfoMessage::GetDeviceFlags (void) const
   4.240 -{
   4.241 -  return m_deviceFlags;
   4.242 -}
   4.243 -uint32_t
   4.244 -InterfaceInfoMessage::GetChangeMask (void) const
   4.245 -{
   4.246 -  return m_changeMask;
   4.247 -}
   4.248 -TypeId 
   4.249 -InterfaceInfoMessage::GetTypeId (void)
   4.250 -{
   4.251 -  static TypeId tid = TypeId ("ns3::InterfaceInfoMessage")
   4.252 -    .SetParent<GeneralMessage> ()
   4.253 -    .AddConstructor<InterfaceInfoMessage> ()
   4.254 -    ;
   4.255 -  return tid;
   4.256 -}
   4.257 -TypeId 
   4.258 -InterfaceInfoMessage::GetInstanceTypeId (void) const
   4.259 -{
   4.260 -  return GetTypeId ();
   4.261 -}
   4.262 -void 
   4.263 -InterfaceInfoMessage::Print (std::ostream &os) const
   4.264 -{  
   4.265 -  os << " ----InterfaceInfoMessage ("
   4.266 -     << "deviceType: " << m_deviceType << " "
   4.267 -     << "interfaceIndex: " << m_interfaceIndex << " "
   4.268 -     << "deviceFlags: " << m_deviceFlags << " "
   4.269 -     << "changeMask: " << m_changeMask << ")" ;
   4.270 -  PrintAttribute (os);
   4.271 -}
   4.272 -uint32_t 
   4.273 -InterfaceInfoMessage::GetSerializedSize (void) const
   4.274 -{
   4.275 -  return NETLINK_INTERFACE_SIZE + GetAttributeSerializedSize ();
   4.276 -}
   4.277 -
   4.278 -void
   4.279 -InterfaceInfoMessage::Serialize (Buffer::Iterator& start) const
   4.280 -{
   4.281 -  start.WriteU8 (m_family);
   4.282 -  start.WriteU8 (m_reserved);
   4.283 -  start.WriteU16 (m_deviceType);
   4.284 -  start.WriteU32 (m_interfaceIndex);
   4.285 -  start.WriteU32 (m_deviceFlags);
   4.286 -  start.WriteU32 (m_changeMask);
   4.287 -
   4.288 -  SerializeAttribute (start);
   4.289 -}
   4.290 -uint32_t
   4.291 -InterfaceInfoMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
   4.292 -{
   4.293 -  m_family = start.ReadU8 ();
   4.294 -  m_reserved = start.ReadU8 ();
   4.295 -  m_deviceType = start.ReadU16 ();
   4.296 -  m_interfaceIndex = start.ReadU32 ();
   4.297 -  m_deviceFlags = start.ReadU32 ();
   4.298 -  m_changeMask = start.ReadU32 ();
   4.299 -
   4.300 -  len -= NETLINK_INTERFACE_SIZE;
   4.301 -
   4.302 -  while (len)
   4.303 -    {
   4.304 -      NetlinkAttribute attr;
   4.305 -
   4.306 -      len -= attr.Deserialize (start, m_attributeTypes);
   4.307 -      m_attributes.push_back (attr);
   4.308 -    }
   4.309 -
   4.310 -  return GetSerializedSize ();
   4.311 -}
   4.312 -
   4.313 -
   4.314 -
   4.315 -/***********************************************************************************
   4.316 -* \InterfaceAddressMessage
   4.317 -***********************************************************************************/
   4.318 -InterfaceAddressMessage::InterfaceAddressMessage ()
   4.319 -  : m_length (0),
   4.320 -    m_flags (0),
   4.321 -    m_scope (0),
   4.322 -    m_index(0)
   4.323 -{
   4.324 -  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
   4.325 -  m_attributeTypes[IF_A_UNSPEC] = UNSPEC;
   4.326 -  m_attributeTypes[IF_A_ADDRESS] = ADDRESS;
   4.327 -  m_attributeTypes[IF_A_LOCAL] = ADDRESS;
   4.328 -  m_attributeTypes[IF_A_LABEL] = STRING;
   4.329 -  m_attributeTypes[IF_A_BROADCAST] = ADDRESS;
   4.330 -  m_attributeTypes[IF_A_ANYCAST] = ADDRESS;
   4.331 -  m_attributeTypes[IF_A_CACHEINFO] = UNSPEC;
   4.332 -  m_attributeTypes[IF_A_MULTICAST] = ADDRESS;
   4.333 -}
   4.334 -InterfaceAddressMessage::~InterfaceAddressMessage ()
   4.335 -{
   4.336 -}
   4.337 -void
   4.338 -InterfaceAddressMessage::SetFamily (uint8_t family)
   4.339 -{
   4.340 -  m_family = family;
   4.341 -}
   4.342 -void
   4.343 -InterfaceAddressMessage::SetLength (uint8_t length)
   4.344 -{
   4.345 -  m_length = length;
   4.346 -}
   4.347 -void
   4.348 -InterfaceAddressMessage::SetFlags (uint8_t flags)
   4.349 -{
   4.350 -  m_flags = flags;
   4.351 -}
   4.352 -void
   4.353 -InterfaceAddressMessage::SetScope (uint8_t scope)
   4.354 -{
   4.355 -  m_scope = scope;
   4.356 -}
   4.357 -void
   4.358 -InterfaceAddressMessage::SetInterfaceIndex (int32_t index)
   4.359 -{
   4.360 -  m_index = index;
   4.361 -}
   4.362 -
   4.363 -uint8_t
   4.364 -InterfaceAddressMessage::GetFamily (void) const
   4.365 -{
   4.366 -  return m_family;
   4.367 -}
   4.368 -uint8_t
   4.369 -InterfaceAddressMessage::GetLength (void) const
   4.370 -{
   4.371 -  return m_length;
   4.372 -}
   4.373 -uint8_t
   4.374 -InterfaceAddressMessage::GetFlags (void) const
   4.375 -{
   4.376 -  return m_flags;
   4.377 -}
   4.378 -uint8_t
   4.379 -InterfaceAddressMessage::GetScope (void) const
   4.380 -{
   4.381 -  return m_scope;
   4.382 -}
   4.383 -int32_t
   4.384 -InterfaceAddressMessage::GetInterfaceIndex (void) const
   4.385 -{
   4.386 -  return m_index;
   4.387 -}
   4.388 -
   4.389 -TypeId 
   4.390 -InterfaceAddressMessage::GetTypeId (void)
   4.391 -{
   4.392 -  static TypeId tid = TypeId ("ns3::InterfaceAddressMessage")
   4.393 -    .SetParent<GeneralMessage> ()
   4.394 -    .AddConstructor<InterfaceAddressMessage> ()
   4.395 -    ;
   4.396 -  return tid;
   4.397 -}
   4.398 -TypeId 
   4.399 -InterfaceAddressMessage::GetInstanceTypeId (void) const
   4.400 -{
   4.401 -  return GetTypeId ();
   4.402 -}
   4.403 -void 
   4.404 -InterfaceAddressMessage::Print (std::ostream &os) const
   4.405 -{  
   4.406 -  os << " ----InterfaceAddressMessage ("
   4.407 -     << "family: " << (uint32_t)m_family << " "
   4.408 -     << "length: " << (uint32_t)m_length << " "
   4.409 -     << "flags: " << (uint32_t)m_flags << " "
   4.410 -     << "scope: " << (uint32_t)m_scope << " "
   4.411 -     << "index: " << m_index << ")";
   4.412 -  PrintAttribute (os);
   4.413 -}
   4.414 -uint32_t 
   4.415 -InterfaceAddressMessage::GetSerializedSize (void) const
   4.416 -{
   4.417 -  return NETLINK_ADDRESS_SIZE + GetAttributeSerializedSize ();
   4.418 -}
   4.419 -
   4.420 -void
   4.421 -InterfaceAddressMessage::Serialize (Buffer::Iterator& start) const
   4.422 -{
   4.423 -  start.WriteU8 (m_family);
   4.424 -  start.WriteU8 (m_length);
   4.425 -  start.WriteU8 (m_flags);
   4.426 -  start.WriteU8 (m_scope);
   4.427 -  start.WriteU32 (m_index);
   4.428 -
   4.429 -  SerializeAttribute(start);
   4.430 -}
   4.431 -
   4.432 -uint32_t
   4.433 -InterfaceAddressMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
   4.434 -{
   4.435 -  m_family = start.ReadU8 ();
   4.436 -  m_length = start.ReadU8 ();
   4.437 -  m_flags = start.ReadU8 ();
   4.438 -  m_scope = start.ReadU8 ();
   4.439 -  m_index = start.ReadU32 ();
   4.440 -
   4.441 -  len -= NETLINK_ADDRESS_SIZE;
   4.442 -
   4.443 -  while (len)
   4.444 -    {
   4.445 -      NetlinkAttribute attr;
   4.446 -
   4.447 -      len -= attr.Deserialize (start, m_attributeTypes);
   4.448 -      m_attributes.push_back (attr);
   4.449 -    }
   4.450 -
   4.451 -  return GetSerializedSize ();
   4.452 -}
   4.453 -
   4.454 -
   4.455 -
   4.456 -/***********************************************************************************
   4.457 -* \ RouteMessage
   4.458 -***********************************************************************************/
   4.459 -RouteMessage::RouteMessage ()
   4.460 -  : m_dstLen (0),
   4.461 -    m_srcLen (0),
   4.462 -    m_tos (0),
   4.463 -    m_tableId (0),
   4.464 -    m_protocol(0),
   4.465 -    m_scope (0),
   4.466 -    m_type (0),
   4.467 -    m_flags (0)
   4.468 -{
   4.469 -  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
   4.470 -  m_attributeTypes[RT_A_UNSPEC] = UNSPEC;
   4.471 -  m_attributeTypes[RT_A_DST] = ADDRESS;
   4.472 -  m_attributeTypes[RT_A_SRC] = ADDRESS;
   4.473 -  m_attributeTypes[RT_A_IIF] = U32;
   4.474 -  m_attributeTypes[RT_A_OIF] = U32;
   4.475 -  m_attributeTypes[RT_A_GATEWAY] = ADDRESS;
   4.476 -  m_attributeTypes[RT_A_PRIORITY] = U8;
   4.477 -  m_attributeTypes[RT_A_PREFSRC] = ADDRESS;
   4.478 -  m_attributeTypes[RT_A_METRICS] = UNSPEC;
   4.479 -  //others default value UNSPEC
   4.480 -}
   4.481 -RouteMessage::~RouteMessage ()
   4.482 -{}
   4.483 -
   4.484 -void
   4.485 -RouteMessage::SetFamily (uint8_t v)
   4.486 -{
   4.487 -  m_family = v;
   4.488 -}
   4.489 -void
   4.490 -RouteMessage::SetDstLength (uint8_t v)
   4.491 -{
   4.492 -  m_dstLen = v;
   4.493 -}
   4.494 -void
   4.495 -RouteMessage::SetSrcLength (uint8_t v)
   4.496 -{
   4.497 -  m_srcLen = v;
   4.498 -}
   4.499 -void
   4.500 -RouteMessage::SetTos (uint8_t v)
   4.501 -{
   4.502 -  m_tos = v;
   4.503 -}
   4.504 -void
   4.505 -RouteMessage::SetTableId (uint8_t v)
   4.506 -{
   4.507 -  m_tableId = v;
   4.508 -}
   4.509 -void
   4.510 -RouteMessage::SetProtocol (uint8_t v)
   4.511 -{
   4.512 -  m_protocol = v;
   4.513 -}
   4.514 -void
   4.515 -RouteMessage::SetScope (uint8_t v)
   4.516 -{
   4.517 -  m_scope = v;
   4.518 -}
   4.519 -void
   4.520 -RouteMessage::SetType (uint8_t v)
   4.521 -{
   4.522 -  m_type = v;
   4.523 -}
   4.524 -void
   4.525 -RouteMessage::SetFlags (uint32_t v)
   4.526 -{
   4.527 -  m_flags = v;
   4.528 -}
   4.529 -uint8_t
   4.530 -RouteMessage::GetFamily (void) const
   4.531 -{
   4.532 -  return m_family;
   4.533 -}
   4.534 -uint8_t
   4.535 -RouteMessage::GetDstLength (void) const
   4.536 -{
   4.537 -  return m_dstLen;
   4.538 -}
   4.539 -uint8_t
   4.540 -RouteMessage::GetSrcLength (void) const
   4.541 -{
   4.542 -  return m_srcLen;
   4.543 -}
   4.544 -uint8_t
   4.545 -RouteMessage::GetTos (void) const
   4.546 -{
   4.547 -  return m_tos;
   4.548 -}
   4.549 -uint8_t
   4.550 -RouteMessage::GetTableId (void) const
   4.551 -{
   4.552 -  return m_tableId;
   4.553 -}
   4.554 -uint8_t
   4.555 -RouteMessage::GetProtocol (void) const
   4.556 -{
   4.557 -  return m_protocol;
   4.558 -}
   4.559 -uint8_t
   4.560 -RouteMessage::GetType (void) const
   4.561 -{
   4.562 -  return m_type;
   4.563 -}
   4.564 -uint8_t
   4.565 -RouteMessage::GetScope (void) const
   4.566 -{
   4.567 -  return m_scope;
   4.568 -}
   4.569 -uint32_t
   4.570 -RouteMessage::GetFlags (void) const
   4.571 -{
   4.572 -  return m_flags;
   4.573 -}
   4.574 -
   4.575 -TypeId 
   4.576 -RouteMessage::GetTypeId (void)
   4.577 -{
   4.578 -  static TypeId tid = TypeId ("ns3::RouteMessage")
   4.579 -    .SetParent<GeneralMessage> ()
   4.580 -    .AddConstructor<RouteMessage> ()
   4.581 -    ;
   4.582 -  return tid;
   4.583 -}
   4.584 -TypeId 
   4.585 -RouteMessage::GetInstanceTypeId (void) const
   4.586 -{
   4.587 -  return GetTypeId ();
   4.588 -}
   4.589 -void 
   4.590 -RouteMessage::Print (std::ostream &os) const
   4.591 -{  
   4.592 -  os << " ----RouteMessage ("
   4.593 -     << "family: " << (uint32_t)m_family << " "
   4.594 -     << "dstLen: " << (uint32_t)m_dstLen << " "
   4.595 -     << "srcLen: " << (uint32_t)m_srcLen << " "
   4.596 -     << "tos: " << (uint32_t)m_tos << " "
   4.597 -     << "tableId: " << (uint32_t)m_tableId << " "
   4.598 -     << "protocol: " << (uint32_t)m_protocol << " "
   4.599 -     << "scope: " << (uint32_t)m_scope << " "
   4.600 -     << "type: " << (uint32_t)m_type << " "
   4.601 -     << "flags: " << m_flags<< ")" ;
   4.602 -  PrintAttribute (os);
   4.603 -}
   4.604 -uint32_t 
   4.605 -RouteMessage::GetSerializedSize (void) const
   4.606 -{
   4.607 -  return NETLINK_ROUTE_SIZE + GetAttributeSerializedSize ();
   4.608 -}
   4.609 -
   4.610 -void
   4.611 -RouteMessage::Serialize (Buffer::Iterator& start) const
   4.612 -{
   4.613 -  start.WriteU8 (m_family);
   4.614 -  start.WriteU8 (m_dstLen);
   4.615 -  start.WriteU8 (m_srcLen);
   4.616 -  start.WriteU8 (m_tos);
   4.617 -  start.WriteU8 (m_tableId);
   4.618 -  start.WriteU8 (m_protocol);
   4.619 -  start.WriteU8 (m_scope);
   4.620 -  start.WriteU8 (m_type);
   4.621 -  start.WriteU32 (m_flags);
   4.622 -
   4.623 -  SerializeAttribute (start);
   4.624 -}
   4.625 -uint32_t
   4.626 -RouteMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
   4.627 -{
   4.628 -  m_family = start.ReadU8 ();
   4.629 -  m_dstLen = start.ReadU8 ();
   4.630 -  m_srcLen = start.ReadU8 ();
   4.631 -  m_tos = start.ReadU8 ();
   4.632 -  m_tableId = start.ReadU8 ();
   4.633 -  m_protocol = start.ReadU8 ();
   4.634 -  m_scope = start.ReadU8 ();
   4.635 -  m_type = start.ReadU8 ();
   4.636 -  m_flags = start.ReadU32 ();
   4.637 -
   4.638 -  len -= NETLINK_ROUTE_SIZE;
   4.639 -
   4.640 -  while (len)
   4.641 -    {
   4.642 -      NetlinkAttribute attr;
   4.643 -
   4.644 -      len -= attr.Deserialize (start, m_attributeTypes);
   4.645 -      m_attributes.push_back (attr);
   4.646 -    }
   4.647 -
   4.648 -  return GetSerializedSize ();
   4.649 -}
   4.650 -}; // namespace ns3
     5.1 --- a/model/netlink-message-route.h	Tue Apr 19 23:13:50 2011 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,388 +0,0 @@
     5.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     5.5 -/*
     5.6 - * Copyright (c) 2008 Liu Jian
     5.7 - *
     5.8 - * This program is free software; you can redistribute it and/or modify
     5.9 - * it under the terms of the GNU General Public License version 2 as
    5.10 - * published by the Free Software Foundation;
    5.11 - *
    5.12 - * This program is distributed in the hope that it will be useful,
    5.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 - * GNU General Public License for more details.
    5.16 - *
    5.17 - * You should have received a copy of the GNU General Public License
    5.18 - * along with this program; if not, write to the Free Software
    5.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.20 - *
    5.21 - * Author: Liu Jian <liujatp@gmail.com>
    5.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    5.23 - */
    5.24 -
    5.25 -#ifndef NETLINK_MESSAGE_ROUTE_H
    5.26 -#define NETLINK_MESSAGE_ROUTE_H
    5.27 -
    5.28 -#include "ns3/object-base.h"
    5.29 -#include "ns3/address.h"
    5.30 -#include "netlink-attribute.h"
    5.31 -#include <string>
    5.32 -
    5.33 -namespace ns3 {
    5.34 -
    5.35 -/*
    5.36 -* this file define some netlink message of NETLINK_ROUTE protocol,
    5.37 -* there are mainly three types:interface address, interface info, route entry
    5.38 -* just implemented them for quagga porting.
    5.39 -*/
    5.40 -  
    5.41 -
    5.42 -
    5.43 -/**
    5.44 -* \Types of messages,here we only define the route message types quagga used
    5.45 -*/
    5.46 -enum NetlinkRtmType_e {
    5.47 -  NETLINK_RTM_BASE = 16,
    5.48 -
    5.49 -  NETLINK_RTM_NEWLINK = 16,
    5.50 -  NETLINK_RTM_DELLINK,
    5.51 -  NETLINK_RTM_GETLINK,
    5.52 -  NETLINK_RTM_SETLINK,
    5.53 -
    5.54 -  NETLINK_RTM_NEWADDR = 20,
    5.55 -  NETLINK_RTM_DELADDR,
    5.56 -  NETLINK_RTM_GETADDR,
    5.57 -
    5.58 -  NETLINK_RTM_NEWROUTE = 24,
    5.59 -  NETLINK_RTM_DELROUTE,
    5.60 -  NETLINK_RTM_GETROUTE,
    5.61 -
    5.62 -  NETLINK_RTM_MAX,
    5.63 -};  
    5.64 -
    5.65 -/**
    5.66 -* \Types of netlink groups,here we only define types quagga used
    5.67 -*/
    5.68 -enum NetlinkRtmGroup_e {
    5.69 -  NETLINK_RTM_GRP_LINK = 1,
    5.70 -  NETLINK_RTM_GRP_IPV4_IFADDR = 0x10,
    5.71 -  NETLINK_RTM_GRP_IPV4_ROUTE = 0x40,
    5.72 -  RTMGRP_IPV6_IFADDR = 0x100,
    5.73 -  RTMGRP_IPV6_ROUTE = 0x400,
    5.74 -};
    5.75 -
    5.76 -class NetlinkPayload :public ObjectBase
    5.77 -{
    5.78 -public:
    5.79 -  static TypeId GetTypeId (void);
    5.80 -  virtual TypeId GetInstanceTypeId (void) const = 0;
    5.81 -  virtual void Serialize (Buffer::Iterator& start) const = 0;
    5.82 -  virtual void Print (std::ostream &os) const = 0;
    5.83 -  virtual uint32_t GetSerializedSize (void) const = 0;
    5.84 -};
    5.85 -
    5.86 -/***
    5.87 - General form of address family dependent message.
    5.88 -
    5.89 -  struct rtgenmsg
    5.90 -  {
    5.91 -    unsigned char		rtgen_family;
    5.92 -  };
    5.93 -**/
    5.94 -
    5.95 -class GeneralMessage : public NetlinkPayload
    5.96 -{
    5.97 -public:
    5.98 -  GeneralMessage ();
    5.99 -  virtual ~GeneralMessage ();
   5.100 -
   5.101 -  static TypeId GetTypeId (void);
   5.102 -  virtual TypeId GetInstanceTypeId (void) const;
   5.103 -  virtual void Serialize (Buffer::Iterator& start) const;
   5.104 -  virtual uint32_t Deserialize (Buffer::Iterator& start);
   5.105 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
   5.106 -  virtual void Print (std::ostream &os) const;
   5.107 -  virtual uint32_t GetSerializedSize (void) const;
   5.108 -
   5.109 -  
   5.110 -  virtual uint32_t GetNNetlinkAttribute (void)const;
   5.111 -  virtual NetlinkAttribute GetNetlinkAttribute (uint32_t index)const;
   5.112 -  virtual void AppendAttribute (NetlinkAttribute v);
   5.113 -  virtual void SerializeAttribute (Buffer::Iterator& start) const;
   5.114 -  virtual void PrintAttribute (std::ostream &os) const;
   5.115 -  virtual uint32_t GetAttributeSerializedSize (void) const;
   5.116 -  virtual bool GetAttributeByType (NetlinkAttribute& attr, uint16_t type);
   5.117 -
   5.118 -
   5.119 -  void SetFamily (uint8_t v);
   5.120 -  uint8_t GetFamily (void) const;
   5.121 -
   5.122 -private:
   5.123 -  static const int NETLINK_GENMSG_SIZE = 1; /* size of the struct rtgenmsg */  
   5.124 -protected:
   5.125 -  uint8_t m_family;   //always set to AF_UNSPEC
   5.126 -  //attribute can exist or not
   5.127 -  std::vector<NetlinkAttribute> m_attributes;
   5.128 -};
   5.129 -
   5.130 -
   5.131 -
   5.132 -/**
   5.133 -* \brief Link layer specific messages
   5.134 -*
   5.135 -* struct ifinfomsg
   5.136 -* passes link level specific information, not dependent
   5.137 -* on network protocol.
   5.138 -*
   5.139 -  struct ifinfomsg
   5.140 -  {
   5.141 -    unsigned char	ifi_family;
   5.142 -    unsigned char	__ifi_pad;
   5.143 -    unsigned short	ifi_type;
   5.144 -    int		ifi_index;	
   5.145 -    unsigned	ifi_flags;
   5.146 -    unsigned	ifi_change;
   5.147 -  };
   5.148 -*/
   5.149 -class InterfaceInfoMessage : public GeneralMessage
   5.150 -{
   5.151 -public:
   5.152 -  InterfaceInfoMessage ();
   5.153 -  virtual ~InterfaceInfoMessage ();
   5.154 -
   5.155 -  static TypeId GetTypeId (void);
   5.156 -  virtual TypeId GetInstanceTypeId (void) const;
   5.157 -  virtual void Serialize (Buffer::Iterator& start) const;
   5.158 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
   5.159 -  virtual void Print (std::ostream &os) const;
   5.160 -  virtual uint32_t GetSerializedSize (void) const;
   5.161 -
   5.162 -  enum IflAttr_e {
   5.163 -    IFL_A_UNSPEC,
   5.164 -    IFL_A_ADDRESS,
   5.165 -    IFL_A_BROADCAST,
   5.166 -    IFL_A_IFNAME,
   5.167 -    IFL_A_MTU,
   5.168 -    IFL_A_LINK,
   5.169 -    IFL_A_QDISC,
   5.170 -    IFL_A_STATS,
   5.171 -    IFL_A_COST,
   5.172 -    IFL_A_PRIORITY,
   5.173 -    IFL_A_MASTER,
   5.174 -    IFL_A_WIRELESS,		
   5.175 -    IFL_A_PROTINFO,
   5.176 -    IFL_A_TXQLEN,
   5.177 -    IFL_A_MAP,
   5.178 -    IFL_A_WEIGHT,
   5.179 -    IFL_A_OPERSTATE,
   5.180 -    IFL_A_LINKMODE,
   5.181 -    IFL_A_MAX,
   5.182 -  };
   5.183 -
   5.184 -  enum Type_e {
   5.185 -    UP = 1,
   5.186 -    BROADCAST = 2,
   5.187 -    DBG = 4,
   5.188 -  };
   5.189 -
   5.190 -  void SetDeviceType (uint16_t type);
   5.191 -  void SetInterfaceIndex (int32_t index);
   5.192 -  void SetDeviceFlags (uint32_t index);
   5.193 -  void SetChangeMask (uint32_t mask);
   5.194 -
   5.195 -  uint16_t GetDeviceType (void) const;
   5.196 -  int32_t GetInterfaceIndex (void) const;
   5.197 -  uint32_t GetDeviceFlags (void) const;
   5.198 -  uint32_t GetChangeMask (void) const;
   5.199 -private:
   5.200 -  static const int NETLINK_INTERFACE_SIZE = 16; /* size of the struct ifinfomsg */
   5.201 -  uint8_t m_reserved; //not used
   5.202 -  uint16_t m_deviceType;
   5.203 -  int32_t m_interfaceIndex;
   5.204 -  uint32_t m_deviceFlags;
   5.205 -  uint32_t m_changeMask;
   5.206 -  NetlinkAttributeValueType m_attributeTypes[IFL_A_MAX];
   5.207 -};
   5.208 -
   5.209 -
   5.210 -
   5.211 -
   5.212 -/**
   5.213 -* \brief Interface address.
   5.214 -*
   5.215 -  struct ifaddrmsg
   5.216 -  {
   5.217 -  unsigned char	ifa_family;
   5.218 -  unsigned char	ifa_prefixlen;
   5.219 -  unsigned char	ifa_flags;
   5.220 -  unsigned char	ifa_scope;
   5.221 -  int		ifa_index;
   5.222 -  };
   5.223 -*/
   5.224 -
   5.225 -class InterfaceAddressMessage : public GeneralMessage
   5.226 -{
   5.227 -public:
   5.228 -  InterfaceAddressMessage ();
   5.229 -  virtual ~InterfaceAddressMessage ();
   5.230 -
   5.231 -  static TypeId GetTypeId (void);
   5.232 -  virtual TypeId GetInstanceTypeId (void) const;
   5.233 -  virtual void Serialize (Buffer::Iterator& start) const;
   5.234 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
   5.235 -  virtual void Print (std::ostream &os) const;
   5.236 -  virtual uint32_t GetSerializedSize (void) const;
   5.237 -
   5.238 -  enum IfAttr_e {
   5.239 -    IF_A_UNSPEC,
   5.240 -    IF_A_ADDRESS,
   5.241 -    IF_A_LOCAL,
   5.242 -    IF_A_LABEL,
   5.243 -    IF_A_BROADCAST,
   5.244 -    IF_A_ANYCAST,
   5.245 -    IF_A_CACHEINFO,
   5.246 -    IF_A_MULTICAST,
   5.247 -    IF_A_MAX
   5.248 -  };
   5.249 -
   5.250 -  enum {
   5.251 -    F_SECONDARY = 0x01,
   5.252 -    F_PERMANENT = 0x80,
   5.253 -    F_DEPRECATED = 0x20,
   5.254 -    F_TENTATIVE = 0x40
   5.255 -  };
   5.256 -  enum {
   5.257 -    SCOPE_UNIVERSE = 0,
   5.258 -    SCOPE_SITE = 200,
   5.259 -    SCOPE_LINK = 253,
   5.260 -    SCOPE_HOST = 254
   5.261 -  };
   5.262 -
   5.263 -
   5.264 -  void SetFamily (uint8_t family);
   5.265 -  void SetLength (uint8_t length);
   5.266 -  void SetFlags (uint8_t flags);
   5.267 -  void SetScope (uint8_t scope);
   5.268 -  void SetInterfaceIndex (int32_t index);
   5.269 -
   5.270 -  uint8_t GetFamily (void) const;
   5.271 -  uint8_t GetLength (void) const;
   5.272 -  uint8_t GetFlags (void) const;
   5.273 -  uint8_t GetScope (void) const;
   5.274 -  int32_t GetInterfaceIndex (void) const;
   5.275 -
   5.276 -private:
   5.277 -  static const int NETLINK_ADDRESS_SIZE = 8; /* size of the struct ifaddrmsg */
   5.278 -  uint8_t m_length;
   5.279 -  uint8_t m_flags;
   5.280 -  uint8_t m_scope;
   5.281 -  int32_t m_index;
   5.282 -  NetlinkAttributeValueType m_attributeTypes[IF_A_MAX];
   5.283 -};
   5.284 -
   5.285 -
   5.286 -/**
   5.287 -* \brief Definitions used in routing table administration.
   5.288 -*
   5.289 -  struct rtmsg
   5.290 -  {
   5.291 -    unsigned char		rtm_family;
   5.292 -    unsigned char		rtm_dst_len;
   5.293 -    unsigned char		rtm_src_len;
   5.294 -    unsigned char		rtm_tos;
   5.295 -
   5.296 -    unsigned char		rtm_table;	// Routing table id 
   5.297 -    unsigned char		rtm_protocol;	//Routing protocol; 
   5.298 -    unsigned char		rtm_scope;	
   5.299 -    unsigned char		rtm_type;	
   5.300 -
   5.301 -    unsigned		rtm_flags;
   5.302 -  };
   5.303 -*/
   5.304 -
   5.305 -class RouteMessage : public GeneralMessage
   5.306 -{
   5.307 -public:
   5.308 -  RouteMessage ();
   5.309 -  virtual ~RouteMessage ();
   5.310 -
   5.311 -  static TypeId GetTypeId (void);
   5.312 -  virtual TypeId GetInstanceTypeId (void) const;
   5.313 -  virtual void Serialize (Buffer::Iterator& start) const;
   5.314 -  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
   5.315 -  virtual void Print (std::ostream &os) const;
   5.316 -  virtual uint32_t GetSerializedSize (void) const;
   5.317 -
   5.318 -  uint8_t GetFamily (void) const;
   5.319 -  uint8_t GetDstLength (void) const;
   5.320 -  uint8_t GetSrcLength (void) const;
   5.321 -  uint8_t GetTos (void) const;
   5.322 -  uint8_t GetTableId (void) const;
   5.323 -  uint8_t GetProtocol(void) const;
   5.324 -  uint8_t GetType (void) const;
   5.325 -  uint8_t GetScope (void) const;
   5.326 -  uint32_t GetFlags (void) const;
   5.327 -  void SetFamily (uint8_t v);
   5.328 -  void SetDstLength (uint8_t v);
   5.329 -  void SetSrcLength (uint8_t v);
   5.330 -  void SetTos (uint8_t v);
   5.331 -  void SetTableId (uint8_t v);
   5.332 -  void SetProtocol (uint8_t v);
   5.333 -  void SetScope (uint8_t v);
   5.334 -  void SetType (uint8_t v);
   5.335 -  void SetFlags (uint32_t v);
   5.336 -
   5.337 -  enum RtProtocol_e {
   5.338 -    RT_PROT_UNSPEC = 0,
   5.339 -  };
   5.340 -
   5.341 -  enum RtFlags_e {
   5.342 -    RT_F_CLONED = 0x200,
   5.343 -  };
   5.344 -
   5.345 -  enum RtScope_e {
   5.346 -    RT_SCOPE_UNIVERSE = 0,
   5.347 -    RT_SCOPE_LINK = 253,
   5.348 -  };
   5.349 -
   5.350 -  enum RtClass_e {
   5.351 -    RT_TABLE_UNSPEC = 0,
   5.352 -    RT_TABLE_MAIN = 254,
   5.353 -  };
   5.354 -
   5.355 -  enum RtAttr_e {
   5.356 -    RT_A_UNSPEC,
   5.357 -    RT_A_DST,
   5.358 -    RT_A_SRC,
   5.359 -    RT_A_IIF,
   5.360 -    RT_A_OIF,
   5.361 -    RT_A_GATEWAY,
   5.362 -    RT_A_PRIORITY,
   5.363 -    RT_A_PREFSRC,
   5.364 -    RT_A_METRICS,
   5.365 -    RT_A_MULTIPATH,
   5.366 -    RT_A_PROTOINFO,
   5.367 -    RT_A_FLOW,
   5.368 -    RT_A_CACHEINFO,
   5.369 -    RT_A_SESSION,
   5.370 -    RT_A_MP_ALGO,
   5.371 -    RT_A_TABLE,
   5.372 -    RT_A_MAX
   5.373 -  };
   5.374 -
   5.375 -
   5.376 -private:
   5.377 -  static const int NETLINK_ROUTE_SIZE = 12; /* size of the struct rtmsg */
   5.378 -  uint8_t m_dstLen;
   5.379 -  uint8_t m_srcLen;
   5.380 -  uint8_t m_tos;
   5.381 -  uint8_t m_tableId;
   5.382 -  uint8_t m_protocol;
   5.383 -  uint8_t m_scope;
   5.384 -  uint8_t m_type;
   5.385 -  uint32_t m_flags;
   5.386 -  NetlinkAttributeValueType m_attributeTypes[RT_A_MAX];
   5.387 -};
   5.388 -
   5.389 -}; // namespace ns3
   5.390 -
   5.391 -#endif /* NETLINK_MESSAGE_ROUTE_H */
     6.1 --- a/model/netlink-message.cc	Tue Apr 19 23:13:50 2011 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,672 +0,0 @@
     6.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     6.5 -/*
     6.6 - * Copyright (c) 2008 Liu Jian
     6.7 - *
     6.8 - * This program is free software; you can redistribute it and/or modify
     6.9 - * it under the terms of the GNU General Public License version 2 as
    6.10 - * published by the Free Software Foundation;
    6.11 - *
    6.12 - * This program is distributed in the hope that it will be useful,
    6.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 - * GNU General Public License for more details.
    6.16 - *
    6.17 - * You should have received a copy of the GNU General Public License
    6.18 - * along with this program; if not, write to the Free Software
    6.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.20 - *
    6.21 - * Author: Liu Jian <liujatp@gmail.com>
    6.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    6.23 - */
    6.24 -
    6.25 -#include "netlink-message.h"
    6.26 -#include "ns3/address-utils.h"
    6.27 -#include "ns3/log.h"
    6.28 -
    6.29 -NS_LOG_COMPONENT_DEFINE ("NetlinkMessage");
    6.30 -
    6.31 -namespace ns3 {
    6.32 -
    6.33 -/***********************************************************************************
    6.34 -* \ NetlinkMessageHeader
    6.35 -***********************************************************************************/
    6.36 -NS_OBJECT_ENSURE_REGISTERED (NetlinkMessageHeader);
    6.37 -NS_OBJECT_ENSURE_REGISTERED (NetlinkMessage);
    6.38 -
    6.39 -NetlinkMessageHeader::NetlinkMessageHeader ()
    6.40 -  : m_nlmsgLen (16),
    6.41 -    m_nlmsgType (0),
    6.42 -    m_nlmsgFlags (0),
    6.43 -    m_nlmsgSeq (0),
    6.44 -    m_nlmsgPid (0)
    6.45 -{}
    6.46 -
    6.47 -NetlinkMessageHeader::NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid)
    6.48 -  : m_nlmsgLen (16),
    6.49 -    m_nlmsgType (type),
    6.50 -    m_nlmsgFlags (flags),
    6.51 -    m_nlmsgSeq (seq),
    6.52 -    m_nlmsgPid (pid)
    6.53 -{}
    6.54 -
    6.55 -void
    6.56 -NetlinkMessageHeader::SetMsgLen (uint32_t v)
    6.57 -{
    6.58 -  m_nlmsgLen = v;
    6.59 -}
    6.60 -void
    6.61 -NetlinkMessageHeader::SetMsgFlags (uint16_t v)
    6.62 -{
    6.63 -  m_nlmsgFlags = v;
    6.64 -}
    6.65 -void
    6.66 -NetlinkMessageHeader::SetMsgType (uint16_t v)
    6.67 -{
    6.68 -  m_nlmsgType = v;
    6.69 -}
    6.70 -void
    6.71 -NetlinkMessageHeader::SetMsgSeq (uint32_t v)
    6.72 -{
    6.73 -  m_nlmsgSeq = v;
    6.74 -}
    6.75 -void
    6.76 -NetlinkMessageHeader::SetMsgPid (uint32_t v)
    6.77 -{
    6.78 -  m_nlmsgPid = v;
    6.79 -}
    6.80 -uint16_t
    6.81 -NetlinkMessageHeader::GetMsgFlags (void) const
    6.82 -{
    6.83 -  return m_nlmsgFlags;
    6.84 -}
    6.85 -uint32_t 
    6.86 -NetlinkMessageHeader::GetMsgLen (void) const
    6.87 -{
    6.88 -  return m_nlmsgLen;
    6.89 -}
    6.90 -uint16_t 
    6.91 -NetlinkMessageHeader::GetMsgType (void) const
    6.92 -{
    6.93 -  return m_nlmsgType;
    6.94 -}
    6.95 -uint32_t
    6.96 -NetlinkMessageHeader::GetMsgSeq (void) const
    6.97 -{
    6.98 -  return m_nlmsgSeq;
    6.99 -}
   6.100 -uint32_t 
   6.101 -NetlinkMessageHeader::GetMsgPid (void) const
   6.102 -{
   6.103 -  return m_nlmsgPid;
   6.104 -}
   6.105 -uint32_t
   6.106 -NetlinkMessageHeader::GetHeaderSize ()
   6.107 -{
   6.108 -  return NETLINK_MSG_HEADER_SIZE;
   6.109 -}
   6.110 -uint32_t
   6.111 -NetlinkMessageHeader::GetPayloadSize (void) const
   6.112 -{
   6.113 -  return NETLINK_MSG_ALIGN (m_nlmsgLen - NETLINK_MSG_HEADER_SIZE);
   6.114 -}
   6.115 -
   6.116 -TypeId 
   6.117 -NetlinkMessageHeader::GetTypeId (void)
   6.118 -{
   6.119 -  static TypeId tid = TypeId ("ns3::NetlinkMessageHeader")
   6.120 -    .SetParent<Header> ()
   6.121 -    .AddConstructor<NetlinkMessageHeader> ()
   6.122 -    ;
   6.123 -  return tid;
   6.124 -}
   6.125 -TypeId 
   6.126 -NetlinkMessageHeader::GetInstanceTypeId (void) const
   6.127 -{
   6.128 -  return GetTypeId ();
   6.129 -}
   6.130 -void 
   6.131 -NetlinkMessageHeader::Print (std::ostream &os) const
   6.132 -{
   6.133 -  os << "NetlinkMessageHeader "
   6.134 -     << "len: " << m_nlmsgLen << " "
   6.135 -     << "flags: " << m_nlmsgFlags << " "
   6.136 -     << "type: " << m_nlmsgType << " "
   6.137 -     << "seq: " << m_nlmsgSeq << " "
   6.138 -     << "pid: " << m_nlmsgPid;
   6.139 -}
   6.140 -
   6.141 -uint32_t 
   6.142 -NetlinkMessageHeader::GetSerializedSize (void) const
   6.143 -{
   6.144 -  /* this is the size of an nlmsghdr payload. */
   6.145 -  return NETLINK_MSG_HEADER_SIZE;
   6.146 -}
   6.147 -
   6.148 -void
   6.149 -NetlinkMessageHeader::Serialize (Buffer::Iterator& start) const
   6.150 -{
   6.151 -  start.WriteU32 (m_nlmsgLen);
   6.152 -  start.WriteU16 (m_nlmsgType);
   6.153 -  start.WriteU16 (m_nlmsgFlags);
   6.154 -  start.WriteU32 (m_nlmsgSeq);
   6.155 -  start.WriteU32 (m_nlmsgPid);
   6.156 -}
   6.157 -
   6.158 -uint32_t
   6.159 -NetlinkMessageHeader::Deserialize (Buffer::Iterator& start)
   6.160 -{
   6.161 -  m_nlmsgLen = start.ReadU32 ();
   6.162 -  m_nlmsgType = start.ReadU16 ();
   6.163 -  m_nlmsgFlags = start.ReadU16 ();
   6.164 -  m_nlmsgSeq = start.ReadU32 ();
   6.165 -  m_nlmsgPid = start.ReadU32 ();
   6.166 -
   6.167 -  return GetSerializedSize ();
   6.168 -}
   6.169 -
   6.170 -
   6.171 -
   6.172 -
   6.173 -/***********************************************************************************
   6.174 -* \ NetlinkMessageError
   6.175 -***********************************************************************************/
   6.176 -
   6.177 -NetlinkMessageError::NetlinkMessageError ()
   6.178 -  : m_error (0)
   6.179 -{
   6.180 -}
   6.181 -NetlinkMessageError::~NetlinkMessageError ()
   6.182 -{}
   6.183 -void 
   6.184 -NetlinkMessageError::SetError (int32_t v)
   6.185 -{
   6.186 -  m_error = v;
   6.187 -}
   6.188 -int32_t
   6.189 -NetlinkMessageError::GetError (void) const
   6.190 -{
   6.191 -  return m_error;
   6.192 -}
   6.193 -void
   6.194 -NetlinkMessageError::SetMsg (NetlinkMessageHeader v)
   6.195 -{
   6.196 -  m_msg = v;
   6.197 -}
   6.198 -NetlinkMessageHeader
   6.199 -NetlinkMessageError::GetMsg (void) const
   6.200 -{
   6.201 -  return m_msg;
   6.202 -}
   6.203 -
   6.204 -TypeId 
   6.205 -NetlinkMessageError::GetTypeId (void)
   6.206 -{
   6.207 -  static TypeId tid = TypeId ("ns3::NetlinkMessageError")
   6.208 -    .SetParent<NetlinkPayload> ()
   6.209 -    .AddConstructor<NetlinkMessageError> ()
   6.210 -    ;
   6.211 -  return tid;
   6.212 -}
   6.213 -
   6.214 -TypeId 
   6.215 -NetlinkMessageError::GetInstanceTypeId (void) const
   6.216 -{
   6.217 -  return GetTypeId ();
   6.218 -}
   6.219 -void 
   6.220 -NetlinkMessageError::Print (std::ostream &os) const
   6.221 -{  
   6.222 -  os << "----NetlinkMessageError "
   6.223 -     << "error: " << m_error << " "
   6.224 -     << "msg:( ";
   6.225 -  m_msg.Print(os);
   6.226 -  os << " )";
   6.227 -}
   6.228 -
   6.229 -uint32_t 
   6.230 -NetlinkMessageError::GetSerializedSize (void) const
   6.231 -{
   6.232 -  /* this is the size of an nlmsgerr payload. */
   6.233 -  return NETLINK_MSG_ERROR_SIZE;
   6.234 -}
   6.235 -
   6.236 -void
   6.237 -NetlinkMessageError::Serialize (Buffer::Iterator& start) const
   6.238 -{
   6.239 -  start.WriteU32 (m_error);
   6.240 -  m_msg.Serialize (start);
   6.241 -}
   6.242 -
   6.243 -uint32_t
   6.244 -NetlinkMessageError::Deserialize (Buffer::Iterator& start)
   6.245 -{  
   6.246 -  m_error = start.ReadU32 ();
   6.247 -  m_msg.Deserialize (start);
   6.248 -  
   6.249 -  return GetSerializedSize ();
   6.250 -}
   6.251 -
   6.252 -
   6.253 -
   6.254 -
   6.255 -/***********************************************************************************
   6.256 -* \ NetlinkMessage
   6.257 -***********************************************************************************/
   6.258 -NetlinkMessage::NetlinkMessage ()
   6.259 -{}
   6.260 -
   6.261 -void
   6.262 -NetlinkMessage::SetHeader (NetlinkMessageHeader hdr)
   6.263 -{
   6.264 -  m_hdr = hdr;
   6.265 -}
   6.266 -NetlinkMessageHeader
   6.267 -NetlinkMessage::GetHeader (void)const
   6.268 -{
   6.269 -  return m_hdr;
   6.270 -}
   6.271 -void
   6.272 -NetlinkMessage::SetGeneralMessage (GeneralMessage genmsg)
   6.273 -{
   6.274 -  m_genmsg = genmsg;
   6.275 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + genmsg.GetSerializedSize ());
   6.276 -}
   6.277 -void
   6.278 -NetlinkMessage::SetErrorMessage (NetlinkMessageError errmsg)
   6.279 -{
   6.280 -  m_errorMessage = errmsg;
   6.281 -  m_hdr.SetMsgLen(m_hdr.GetSerializedSize () + errmsg.GetSerializedSize ());
   6.282 -}
   6.283 -// the type is one of RTM_NEWLINK,RTM_DELLINK,RTM_GETLINK
   6.284 -void
   6.285 -NetlinkMessage::SetInterfaceInfoMessage (InterfaceInfoMessage v)
   6.286 -{
   6.287 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
   6.288 -  m_interfaceTemplate = v;
   6.289 -}
   6.290 -// the type is one of RTM_NEWADDR,RTM_DELADDR,RTM_GETADDR
   6.291 -void NetlinkMessage::SetInterfaceAddressMessage (InterfaceAddressMessage v)
   6.292 -{
   6.293 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
   6.294 -  m_addressTemplate = v;
   6.295 -}
   6.296 -// the type  is one of RTM_NEWROUTE,RTM_DELROUTE,RTM_GETROUTE
   6.297 -void NetlinkMessage::SetRouteMessage (RouteMessage v)
   6.298 -{
   6.299 -  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
   6.300 -  m_routeTemplate = v;
   6.301 -}
   6.302 -GeneralMessage
   6.303 -NetlinkMessage::GetGeneralMessage (void) const
   6.304 -{
   6.305 -  return m_genmsg;
   6.306 -}
   6.307 -NetlinkMessageError
   6.308 -NetlinkMessage::GetErrorMessage (void) const
   6.309 -{
   6.310 -  return m_errorMessage;
   6.311 -}
   6.312 -InterfaceInfoMessage
   6.313 -NetlinkMessage::GetInterfaceInfoMessage (void) const
   6.314 -{
   6.315 -  return m_interfaceTemplate;
   6.316 -}
   6.317 -InterfaceAddressMessage
   6.318 -NetlinkMessage::GetInterfaceAddressMessage (void) const
   6.319 -{
   6.320 -  return m_addressTemplate;
   6.321 -}
   6.322 -RouteMessage
   6.323 -NetlinkMessage::GetRouteMessage (void) const
   6.324 -{
   6.325 -  return m_routeTemplate;
   6.326 -}
   6.327 -bool
   6.328 -NetlinkMessage::IsMessageNetlinkControl (uint16_t type)
   6.329 -{
   6.330 -  return (type < NETLINK_RTM_BASE);
   6.331 -}
   6.332 -bool
   6.333 -NetlinkMessage::IsMessageNetlinkRoute (uint16_t type)
   6.334 -{
   6.335 -  return (type >= NETLINK_RTM_BASE && type < NETLINK_RTM_MAX);
   6.336 -}
   6.337 -bool
   6.338 -NetlinkMessage::IsMessageAddress (uint16_t type)
   6.339 -{
   6.340 -  return (type >= NETLINK_RTM_NEWADDR && type <= NETLINK_RTM_GETADDR);
   6.341 -}
   6.342 -bool
   6.343 -NetlinkMessage::IsMessageInterface (uint16_t type)
   6.344 -{
   6.345 -  return (type >= NETLINK_RTM_NEWLINK && type <= NETLINK_RTM_SETLINK);
   6.346 -}
   6.347 -bool
   6.348 -NetlinkMessage::IsMessageRoute (uint16_t type)
   6.349 -{
   6.350 -  return (type >= NETLINK_RTM_NEWROUTE && type <= NETLINK_RTM_GETROUTE);
   6.351 -}
   6.352 -bool
   6.353 -NetlinkMessage::IsMessageTypeGet (uint16_t type)
   6.354 -{
   6.355 -  return ((( type - NETLINK_RTM_BASE)&3) == 2);
   6.356 -}
   6.357 -bool
   6.358 -NetlinkMessage::IsMessageFlagsAck (uint16_t flags)
   6.359 -{
   6.360 -  return (flags & NETLINK_MSG_F_ACK) ? true : false;
   6.361 -}
   6.362 -bool
   6.363 -NetlinkMessage::IsMessageFlagsRequest (uint16_t flags)
   6.364 -{
   6.365 -  return (flags & NETLINK_MSG_F_REQUEST) ? true : false;
   6.366 -}
   6.367 -bool
   6.368 -NetlinkMessage::IsMessageFlagsDump (uint16_t flags)
   6.369 -{
   6.370 -  return (flags & NETLINK_MSG_F_DUMP) ? true : false;
   6.371 -}
   6.372 -
   6.373 -NetlinkMessage::operator MultipartNetlinkMessage (void) const
   6.374 -{
   6.375 -  MultipartNetlinkMessage multi_nlmsg;
   6.376 -  multi_nlmsg.AppendMessage (*this);
   6.377 -  return multi_nlmsg;
   6.378 -}
   6.379 -
   6.380 -TypeId 
   6.381 -NetlinkMessage::GetTypeId (void)
   6.382 -{
   6.383 -  static TypeId tid = TypeId ("ns3::NetlinkMessage")
   6.384 -    .SetParent<Header> ()
   6.385 -    .AddConstructor<NetlinkMessage> ()
   6.386 -    ;
   6.387 -  return tid;
   6.388 -}
   6.389 -TypeId 
   6.390 -NetlinkMessage::GetInstanceTypeId (void) const
   6.391 -{
   6.392 -  return GetTypeId ();
   6.393 -}
   6.394 -
   6.395 -uint32_t
   6.396 -NetlinkMessage::GetTotalSize (void) const
   6.397 -{
   6.398 -  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
   6.399 -}
   6.400 -
   6.401 -uint32_t
   6.402 -NetlinkMessage::GetMsgSize (void) const
   6.403 -{
   6.404 -  return m_hdr.GetMsgLen ();
   6.405 -}
   6.406 -
   6.407 -uint32_t
   6.408 -NetlinkMessage::GetPayloadSize (void) const
   6.409 -{
   6.410 -  return m_hdr.GetPayloadSize ();
   6.411 -}
   6.412 -uint16_t
   6.413 -NetlinkMessage::GetMsgType (void) const
   6.414 -{
   6.415 -  return m_hdr.GetMsgType ();
   6.416 -}
   6.417 -
   6.418 -uint8_t
   6.419 -NetlinkMessage::GetFamily(void) const
   6.420 -{
   6.421 -  if (IsMessageTypeGet (GetMsgType ()))
   6.422 -    {
   6.423 -      NS_LOG_DEBUG ("TypeGetMsg");
   6.424 -    }
   6.425 -  if (IsMessageAddress (m_hdr.GetMsgType ()))
   6.426 -    {
   6.427 -      return m_addressTemplate.GetFamily ();
   6.428 -    }
   6.429 -  else if (IsMessageInterface(m_hdr.GetMsgType ()))
   6.430 -    {
   6.431 -      return m_interfaceTemplate.GetFamily ();
   6.432 -    }
   6.433 -  else if (IsMessageRoute(m_hdr.GetMsgType ()))
   6.434 -    {
   6.435 -      return m_routeTemplate.GetFamily ();
   6.436 -    }
   6.437 -  else if (IsMessageFlagsDump (m_hdr.GetMsgFlags ()))
   6.438 -    {
   6.439 -      return m_genmsg.GetFamily (); //value is said to be always set to AF_UNSPEC
   6.440 -    }
   6.441 -  else
   6.442 -    {
   6.443 -      NS_LOG_WARN ("Netlink message type not supported, return AF_UNSPEC");
   6.444 -      return 0;
   6.445 -    }
   6.446 -}
   6.447 -
   6.448 -void 
   6.449 -NetlinkMessage::Print (std::ostream &os) const
   6.450 -{
   6.451 -  uint16_t type = m_hdr.GetMsgType ();
   6.452 -
   6.453 -  os << "NetlinkMessage  ";
   6.454 -  os << " ----Header:(";
   6.455 -  m_hdr.Print(os);
   6.456 -  os << ")";
   6.457 -
   6.458 -  if (type == NETLINK_MSG_DONE )
   6.459 -    {
   6.460 -      os << "multipart message ends here";
   6.461 -    }
   6.462 -  else if (type == NETLINK_MSG_ERROR )
   6.463 -    {
   6.464 -      m_errorMessage.Print (os);
   6.465 -    }
   6.466 -  else if (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK)
   6.467 -    {
   6.468 -      m_genmsg.Print (os);
   6.469 -    }  
   6.470 -  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE)
   6.471 -    {
   6.472 -      m_routeTemplate.Print (os);
   6.473 -    }
   6.474 -  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
   6.475 -    {
   6.476 -      m_addressTemplate.Print (os);
   6.477 -    }
   6.478 -  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_DELLINK)
   6.479 -    {
   6.480 -      m_interfaceTemplate.Print (os);
   6.481 -    }
   6.482 -  else
   6.483 -    {
   6.484 -      os << "service not supported yet( " << type <<")";
   6.485 -    }
   6.486 -}
   6.487 -uint32_t 
   6.488 -NetlinkMessage::GetSerializedSize (void) const
   6.489 -{
   6.490 -  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
   6.491 -}
   6.492 -
   6.493 -void
   6.494 -NetlinkMessage::Serialize (Buffer::Iterator& start) const
   6.495 -{
   6.496 -  NS_LOG_FUNCTION (this);
   6.497 -  //  Print (std::cout);
   6.498 -  uint16_t type = m_hdr.GetMsgType ();
   6.499 -
   6.500 -  m_hdr.Serialize (start);
   6.501 -
   6.502 -  if (type == NETLINK_MSG_DONE)
   6.503 -    {
   6.504 -      //nothing done
   6.505 -    }
   6.506 -  else if (type == NETLINK_MSG_ERROR)
   6.507 -    {
   6.508 -      m_errorMessage.Serialize (start);
   6.509 -    }  
   6.510 -  else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags ()) && 
   6.511 -           (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
   6.512 -    {
   6.513 -      m_genmsg.Serialize (start);
   6.514 -    }  
   6.515 -  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
   6.516 -    {
   6.517 -      m_routeTemplate.Serialize (start);
   6.518 -    }
   6.519 -  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
   6.520 -    {
   6.521 -      m_addressTemplate.Serialize (start);
   6.522 -    }
   6.523 -  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
   6.524 -    {
   6.525 -      m_interfaceTemplate.Serialize (start);
   6.526 -    }
   6.527 -  else
   6.528 -    {
   6.529 -    }  
   6.530 -}
   6.531 -
   6.532 -
   6.533 -uint32_t
   6.534 -NetlinkMessage::Deserialize (Buffer::Iterator&start)
   6.535 -{
   6.536 -  uint32_t remaining;
   6.537 -
   6.538 -  m_hdr.Deserialize (start);
   6.539 -  remaining = NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ()) - m_hdr.GetSerializedSize ();
   6.540 -  
   6.541 -  //Deserialize service module
   6.542 -  uint16_t type = GetMsgType ();
   6.543 -  if (remaining)
   6.544 -    {        
   6.545 -      if (type == NETLINK_MSG_DONE)
   6.546 -        {
   6.547 -          //do nothing
   6.548 -        }
   6.549 -      else if (type == NETLINK_MSG_ERROR)
   6.550 -        {
   6.551 -          remaining -= m_errorMessage.Deserialize (start);
   6.552 -        }      
   6.553 -      else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags()) &&
   6.554 -               (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
   6.555 -        {
   6.556 -          remaining -= m_genmsg.Deserialize (start, remaining);
   6.557 -        }
   6.558 -      else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
   6.559 -        {
   6.560 -          remaining -= m_routeTemplate.Deserialize (start, remaining);
   6.561 -        }
   6.562 -      else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
   6.563 -        {
   6.564 -          remaining -= m_addressTemplate.Deserialize (start, remaining);
   6.565 -        }
   6.566 -      else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
   6.567 -        {
   6.568 -          remaining -= m_interfaceTemplate.Deserialize (start, remaining);
   6.569 -        }
   6.570 -      else
   6.571 -        {
   6.572 -          //do nothing
   6.573 -        }
   6.574 -    }
   6.575 -
   6.576 -  return GetSerializedSize ();
   6.577 -}
   6.578 -
   6.579 -
   6.580 -/***********************************************************************************
   6.581 -* \ MultipartNetlinkMessage
   6.582 -***********************************************************************************/
   6.583 -MultipartNetlinkMessage::MultipartNetlinkMessage ()
   6.584 -{}
   6.585 -
   6.586 -TypeId 
   6.587 -MultipartNetlinkMessage::GetTypeId (void)
   6.588 -{
   6.589 -  static TypeId tid = TypeId ("ns3::MultipartNetlinkMessage")
   6.590 -    .SetParent<Header> ()
   6.591 -    .AddConstructor<MultipartNetlinkMessage> ()
   6.592 -    ;
   6.593 -  return tid;
   6.594 -}
   6.595 -TypeId 
   6.596 -MultipartNetlinkMessage::GetInstanceTypeId (void) const
   6.597 -{
   6.598 -  return GetTypeId ();
   6.599 -}
   6.600 -
   6.601 -void
   6.602 -MultipartNetlinkMessage::Print (std::ostream &os) const
   6.603 -{
   6.604 -  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
   6.605 -    {
   6.606 -      m_netlinkMessages[i].Print (os);
   6.607 -    }
   6.608 -}
   6.609 -uint32_t
   6.610 -MultipartNetlinkMessage::GetSerializedSize (void) const
   6.611 -{
   6.612 -  uint32_t len = 0;
   6.613 -
   6.614 -  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
   6.615 -    {
   6.616 -      len +=  m_netlinkMessages[i].GetSerializedSize ();
   6.617 -    }
   6.618 -  return len;
   6.619 -}
   6.620 -void
   6.621 -MultipartNetlinkMessage::Serialize (Buffer::Iterator start) const
   6.622 -{
   6.623 -  NS_LOG_FUNCTION ("Multi" << this);
   6.624 -  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
   6.625 -    {
   6.626 -      m_netlinkMessages[i].Serialize (start);
   6.627 -    }
   6.628 -}
   6.629 -uint32_t
   6.630 -MultipartNetlinkMessage::Deserialize (Buffer::Iterator start)
   6.631 -{
   6.632 -  while (1)
   6.633 -    {
   6.634 -      NetlinkMessage nlmsg;
   6.635 -      nlmsg.Deserialize (start);
   6.636 -      AppendMessage (nlmsg);
   6.637 -
   6.638 -      if (!(nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_MULTI))
   6.639 -        {
   6.640 -          break;
   6.641 -        }
   6.642 -
   6.643 -      if (nlmsg.GetHeader ().GetMsgType() == NETLINK_MSG_DONE)
   6.644 -        {
   6.645 -          break;
   6.646 -        }
   6.647 -    }
   6.648 -  return GetSerializedSize ();
   6.649 -}
   6.650 -
   6.651 -void
   6.652 -MultipartNetlinkMessage::AppendMessage (NetlinkMessage nlmsg)
   6.653 -{
   6.654 -  m_netlinkMessages.push_back (nlmsg);
   6.655 -}
   6.656 -
   6.657 -void
   6.658 -MultipartNetlinkMessage::Clear ()
   6.659 -{
   6.660 -  m_netlinkMessages.clear ();
   6.661 -}
   6.662 -
   6.663 -uint32_t
   6.664 -MultipartNetlinkMessage::GetNMessages (void) const
   6.665 -{
   6.666 -  return m_netlinkMessages.size ();
   6.667 -}
   6.668 -NetlinkMessage
   6.669 -MultipartNetlinkMessage::GetMessage (uint32_t index) const
   6.670 -{
   6.671 -  NS_ASSERT(index < m_netlinkMessages.size ());
   6.672 -  return m_netlinkMessages[index];
   6.673 -}
   6.674 -
   6.675 -}; // namespace ns3
     7.1 --- a/model/netlink-message.h	Tue Apr 19 23:13:50 2011 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,256 +0,0 @@
     7.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     7.5 -/*
     7.6 - * Copyright (c) 2008 Liu Jian
     7.7 - *
     7.8 - * This program is free software; you can redistribute it and/or modify
     7.9 - * it under the terms of the GNU General Public License version 2 as
    7.10 - * published by the Free Software Foundation;
    7.11 - *
    7.12 - * This program is distributed in the hope that it will be useful,
    7.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.15 - * GNU General Public License for more details.
    7.16 - *
    7.17 - * You should have received a copy of the GNU General Public License
    7.18 - * along with this program; if not, write to the Free Software
    7.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.20 - *
    7.21 - * Author: Liu Jian <liujatp@gmail.com>
    7.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    7.23 - */
    7.24 -
    7.25 -#ifndef NETLINK_MESSAGE_H
    7.26 -#define NETLINK_MESSAGE_H
    7.27 -
    7.28 -#include "ns3/header.h"
    7.29 -#include "ns3/address.h"
    7.30 -#include "netlink-message-route.h"
    7.31 -#include "netlink-attribute.h"
    7.32 -
    7.33 -
    7.34 -namespace ns3 {
    7.35 -  class NetlinkPayload;
    7.36 -  class GeneralMessage;
    7.37 -  class InterfaceAddressMessage;
    7.38 -  class InterfaceInfoMessage;
    7.39 -  class RouteMessage;
    7.40 -  class MultipartNetlinkMessage;
    7.41 -
    7.42 -/**
    7.43 -* \brief The Netlink message structure for an netlink packet
    7.44 -* 
    7.45 -There are three levels to a Netlink message: The general Netlink
    7.46 -message header, the IP service specific template, and the IP service
    7.47 -specific data.
    7.48 -
    7.49 -0                   1                   2                   3
    7.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
    7.51 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    7.52 -|                                                               |
    7.53 -|                   Netlink message header                      |
    7.54 -|                                                               |
    7.55 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    7.56 -|                                                               |
    7.57 -|                  IP Service Template                          |
    7.58 -|                                                               |
    7.59 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    7.60 -|                                                               |
    7.61 -|                  IP Service specific data in TLVs             |
    7.62 -|                                                               |
    7.63 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    7.64 -*/
    7.65 -
    7.66 -  enum NetlinkMessageFlag
    7.67 -  {
    7.68 -    NETLINK_MSG_F_REQUEST = 1,  // It is request message.
    7.69 -    NETLINK_MSG_F_MULTI = 2,    // Multipart message, terminated by NETLINK_MSG_DONE
    7.70 -    NETLINK_MSG_F_ACK = 4,      // Reply with ack, with zero or error code
    7.71 -    NETLINK_MSG_F_ECHO = 8,     // Echo this request 
    7.72 -
    7.73 -    /* Modifiers to Get request */
    7.74 -    NETLINK_MSG_F_ROOT = 0x100,        // specify tree root
    7.75 -    NETLINK_MSG_F_MATCH = 0x200,       // return all matching
    7.76 -    NETLINK_MSG_F_ATOMIC = 0x400,      // atomic Get =
    7.77 -    NETLINK_MSG_F_DUMP = (NETLINK_MSG_F_ROOT|NETLINK_MSG_F_MATCH),
    7.78 -
    7.79 -    /* Modifiers to NEW request */
    7.80 -    NETLINK_MSG_F_REPLACE = 0x100, // Override existing = 
    7.81 -    NETLINK_MSG_F_EXCL = 0x200,   // Do not touch, if it exists
    7.82 -    NETLINK_MSG_F_CREATE = 0x400,  // Create, if it does not exist
    7.83 -    NETLINK_MSG_F_APPEND = 0x800,  // Add to end of list = 
    7.84 -  };
    7.85 -
    7.86 -  enum NetlinkMessageType
    7.87 -  {
    7.88 -    NETLINK_MSG_NOOP = 0x1,          // Nothing.
    7.89 -    NETLINK_MSG_ERROR = 0x2,         // Error
    7.90 -    NETLINK_MSG_DONE = 0x3,          // End of a dump
    7.91 -    NETLINK_MSG_OVERRUN = 0x4,       // Data lost
    7.92 -    NETLINK_MSG_MIN_TYPE = 0x10,     // < 0x10: reserved control messages
    7.93 -  };
    7.94 -
    7.95 -#define NETLINK_MSG_ALIGNTO 4
    7.96 -#define NETLINK_MSG_ALIGN(X)    (((X)+NETLINK_MSG_ALIGNTO-1) & ~(NETLINK_MSG_ALIGNTO-1) )
    7.97 -
    7.98 -class NetlinkMessageHeader : public ObjectBase
    7.99 -{
   7.100 -public:
   7.101 -  NetlinkMessageHeader ();
   7.102 -  NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid);
   7.103 -
   7.104 -  static TypeId GetTypeId (void);
   7.105 -  virtual TypeId GetInstanceTypeId (void) const;
   7.106 -  void Print (std::ostream &os) const;
   7.107 -  uint32_t GetSerializedSize (void) const;
   7.108 -  void Serialize (Buffer::Iterator& start) const;
   7.109 -  uint32_t Deserialize (Buffer::Iterator& start);
   7.110 -
   7.111 -  void SetMsgLen (uint32_t v);
   7.112 -  void SetMsgFlags (uint16_t v);
   7.113 -  void SetMsgType (uint16_t v);
   7.114 -  void SetMsgSeq (uint32_t v);
   7.115 -  void SetMsgPid (uint32_t v);
   7.116 -  uint32_t GetMsgLen (void) const;
   7.117 -  uint16_t GetMsgFlags (void) const;
   7.118 -  uint16_t GetMsgType (void) const;
   7.119 -  uint32_t GetMsgSeq (void) const;
   7.120 -  uint32_t GetMsgPid (void) const;
   7.121 -
   7.122 -  static uint32_t GetHeaderSize ();
   7.123 -  uint32_t GetPayloadSize (void) const;
   7.124 -
   7.125 -private:
   7.126 -  static const uint32_t NETLINK_MSG_HEADER_SIZE = 16; /* size of the nlmsghdr field*/
   7.127 -  uint32_t m_nlmsgLen;	/* Length of message including header */
   7.128 -  uint16_t m_nlmsgType;	/* Message content */
   7.129 -  uint16_t m_nlmsgFlags;	/* Additional flags */
   7.130 -  uint32_t m_nlmsgSeq;	/* Sequence number */
   7.131 -  uint32_t m_nlmsgPid;	/* Sending process PID */
   7.132 -};
   7.133 -
   7.134 -/**
   7.135 -* \brief The struct nlmsgerr
   7.136 -*/
   7.137 -class NetlinkMessageError : public NetlinkPayload
   7.138 -{
   7.139 -public:
   7.140 -  NetlinkMessageError ();
   7.141 -  virtual ~NetlinkMessageError();
   7.142 -
   7.143 -  static TypeId GetTypeId (void);
   7.144 -  virtual TypeId GetInstanceTypeId (void) const;
   7.145 -  virtual void Serialize (Buffer::Iterator& start) const;
   7.146 -  virtual uint32_t Deserialize (Buffer::Iterator& start);
   7.147 -  virtual void Print (std::ostream &os) const;
   7.148 -  virtual uint32_t GetSerializedSize (void) const;
   7.149 -
   7.150 -  void SetError (int32_t v);
   7.151 -  int32_t GetError (void) const;
   7.152 -  void SetMsg(NetlinkMessageHeader v);
   7.153 -  NetlinkMessageHeader GetMsg (void) const;
   7.154 -
   7.155 -private:
   7.156 -  static const int NETLINK_MSG_ERROR_SIZE = 20; /* size of the nlmsgerror field*/
   7.157 -  int32_t m_error;
   7.158 -  NetlinkMessageHeader m_msg;        
   7.159 -};
   7.160 -
   7.161 -
   7.162 -class NetlinkMessage : public ObjectBase
   7.163 -{
   7.164 -public:
   7.165 -  NetlinkMessage ();
   7.166 -
   7.167 -  static TypeId GetTypeId (void);
   7.168 -  TypeId GetInstanceTypeId (void) const;
   7.169 -  void Print (std::ostream &os) const;
   7.170 -  uint32_t GetSerializedSize (void) const;
   7.171 -  void Serialize (Buffer::Iterator& start) const;
   7.172 -  uint32_t Deserialize (Buffer::Iterator& start);
   7.173 -
   7.174 -  operator MultipartNetlinkMessage (void) const;
   7.175 -
   7.176 -  uint32_t GetTotalSize (void) const;  //length of netlink message including padding
   7.177 -  uint32_t GetMsgSize (void) const;    //length of netlink message not including padding
   7.178 -  uint32_t GetPayloadSize (void) const; //length of message payload
   7.179 -  uint16_t GetMsgType (void) const;
   7.180 -  uint8_t GetFamily(void) const;
   7.181 -
   7.182 -  void SetHeader (NetlinkMessageHeader hdr);
   7.183 -  NetlinkMessageHeader GetHeader (void) const;
   7.184 -
   7.185 -  //before set message body, should set header first
   7.186 -  void SetErrorMessage (NetlinkMessageError errmsg);
   7.187 -  void SetGeneralMessage (GeneralMessage genmsg);
   7.188 -  void SetInterfaceInfoMessage (InterfaceInfoMessage v);
   7.189 -  void SetInterfaceAddressMessage (InterfaceAddressMessage v);
   7.190 -  void SetRouteMessage (RouteMessage v);
   7.191 -  NetlinkMessageError GetErrorMessage (void) const;
   7.192 -  GeneralMessage GetGeneralMessage (void) const;
   7.193 -  InterfaceInfoMessage GetInterfaceInfoMessage (void) const;
   7.194 -  InterfaceAddressMessage GetInterfaceAddressMessage (void) const;
   7.195 -  RouteMessage GetRouteMessage (void) const;
   7.196 -
   7.197 -  /**
   7.198 -  * \returns true if type was control type, false otherwise.
   7.199 -  */
   7.200 -  static bool IsMessageNetlinkControl (uint16_t type);
   7.201 -  /**
   7.202 -  * \returns true if type was netlink route, false otherwise.
   7.203 -  */
   7.204 -  static bool IsMessageNetlinkRoute (uint16_t type);
   7.205 -  static bool IsMessageAddress (uint16_t type);
   7.206 -  static bool IsMessageInterface (uint16_t type);
   7.207 -  static bool IsMessageRoute (uint16_t type);
   7.208 -  /**
   7.209 -  * \returns true if type was GETxxx , false otherwise.
   7.210 -  */
   7.211 -  static bool IsMessageTypeGet (uint16_t type);
   7.212 -  /**
   7.213 -  * \returns true if flag has ack , false otherwise.
   7.214 -  */
   7.215 -  static bool IsMessageFlagsAck (uint16_t flags);
   7.216 -  /**
   7.217 -  * \returns true if flag has request , false otherwise.
   7.218 -  */
   7.219 -  static bool IsMessageFlagsRequest (uint16_t flags);
   7.220 -  /**
   7.221 -  * \returns true if flag has dump , false otherwise.
   7.222 -  */
   7.223 -  static bool IsMessageFlagsDump (uint16_t flags);
   7.224 -
   7.225 -private:
   7.226 -  NetlinkMessageHeader m_hdr;
   7.227 -
   7.228 -  //only one type of messages below exists in real world application
   7.229 -  NetlinkMessageError m_errorMessage;  
   7.230 -  GeneralMessage m_genmsg;
   7.231 -  InterfaceInfoMessage m_interfaceTemplate;
   7.232 -  InterfaceAddressMessage m_addressTemplate;
   7.233 -  RouteMessage m_routeTemplate;
   7.234 -};
   7.235 -
   7.236 -class MultipartNetlinkMessage : public Header
   7.237 -{
   7.238 -public:
   7.239 -  MultipartNetlinkMessage ();
   7.240 -
   7.241 -  static TypeId GetTypeId (void);
   7.242 -  virtual TypeId GetInstanceTypeId (void) const;
   7.243 -  virtual void Print (std::ostream &os) const;
   7.244 -  virtual uint32_t GetSerializedSize (void) const;
   7.245 -  virtual void Serialize (Buffer::Iterator start) const;
   7.246 -  virtual uint32_t Deserialize (Buffer::Iterator start);
   7.247 -
   7.248 -  void AppendMessage (NetlinkMessage nlmsg);
   7.249 -  void Clear();
   7.250 -  uint32_t GetNMessages (void) const;
   7.251 -  NetlinkMessage GetMessage (uint32_t index) const;
   7.252 -
   7.253 -private:
   7.254 -  std::vector<NetlinkMessage> m_netlinkMessages;
   7.255 -};
   7.256 -
   7.257 -}; // namespace ns3
   7.258 -
   7.259 -#endif /* NETLINK_MESSAGE_H */
     8.1 --- a/model/netlink-socket-address.cc	Tue Apr 19 23:13:50 2011 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,121 +0,0 @@
     8.4 -/* -*-	Mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     8.5 -/*
     8.6 - * Copyright (c) 2008 Liu Jian
     8.7 - *
     8.8 - * This program is free software; you can redistribute it and/or modify
     8.9 - * it under the terms of the GNU General Public License version 2 as
    8.10 - * published by the Free Software Foundation;
    8.11 - *
    8.12 - * This program is distributed in the hope that it will be useful,
    8.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 - * GNU General Public License for more details.
    8.16 - *
    8.17 - * You should have received a copy of the GNU General Public License
    8.18 - * along with this program; if not, write to the Free Software
    8.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.20 - *
    8.21 - * Author: Liu Jian <liujatp@gmail.com>
    8.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    8.23 - */
    8.24 -
    8.25 -#include "netlink-socket-address.h"
    8.26 -
    8.27 -namespace ns3 {
    8.28 -
    8.29 -NetlinkSocketAddress::NetlinkSocketAddress (uint32_t pid, uint32_t groups)
    8.30 -  : m_pid(pid),
    8.31 -    m_groups(groups)
    8.32 -{}
    8.33 -
    8.34 -NetlinkSocketAddress::NetlinkSocketAddress ()
    8.35 -  : m_pid (0),
    8.36 -    m_groups (0)
    8.37 -{}
    8.38 -
    8.39 -NetlinkSocketAddress::~NetlinkSocketAddress ()
    8.40 -{}
    8.41 -
    8.42 -void NetlinkSocketAddress::SetProcessID (uint32_t pid)
    8.43 -{
    8.44 -  m_pid = pid;
    8.45 -}
    8.46 -
    8.47 -void NetlinkSocketAddress::SetGroupsMask (uint32_t mask)
    8.48 -{
    8.49 -  m_groups = mask;
    8.50 -}
    8.51 -
    8.52 -uint32_t NetlinkSocketAddress::GetProcessID (void) const
    8.53 -{
    8.54 -  return m_pid;
    8.55 -}
    8.56 -
    8.57 -uint32_t NetlinkSocketAddress::GetGroupsMask (void) const
    8.58 -{
    8.59 -  return m_groups;
    8.60 -}
    8.61 -
    8.62 -NetlinkSocketAddress::operator Address (void) const
    8.63 -{
    8.64 -  return ConvertTo ();
    8.65 -}
    8.66 -
    8.67 -Address NetlinkSocketAddress::ConvertTo (void) const
    8.68 -{
    8.69 -  uint8_t buffer[8];
    8.70 -
    8.71 -  buffer[0] = (m_pid >> 24) & 0xff;
    8.72 -  buffer[1] = (m_pid >> 16) & 0xff;
    8.73 -  buffer[2] = (m_pid >> 8) & 0xff;
    8.74 -  buffer[3] = (m_pid >> 0) & 0xff;
    8.75 -  buffer[4] = (m_groups >> 24) & 0xff;
    8.76 -  buffer[5] = (m_groups >> 16) & 0xff;
    8.77 -  buffer[6] = (m_groups >> 8) & 0xff;
    8.78 -  buffer[7] = (m_groups >> 0) & 0xff;
    8.79 -
    8.80 -  return Address (GetType (), buffer, 8);
    8.81 -}
    8.82 -
    8.83 -NetlinkSocketAddress NetlinkSocketAddress::ConvertFrom (const Address &address)
    8.84 -{
    8.85 -  NS_ASSERT (IsMatchingType (address));
    8.86 -
    8.87 -  NetlinkSocketAddress nl;
    8.88 -  uint8_t buf[8];
    8.89 -
    8.90 -  address.CopyTo (buf);
    8.91 -
    8.92 -  nl.m_pid = 0;
    8.93 -  nl.m_pid |= buf[0];
    8.94 -  nl.m_pid <<= 8;
    8.95 -  nl.m_pid |= buf[1];
    8.96 -  nl.m_pid <<= 8;
    8.97 -  nl.m_pid |= buf[2];
    8.98 -  nl.m_pid <<= 8;
    8.99 -  nl.m_pid |= buf[3];
   8.100 -
   8.101 -  nl.m_groups = 0;
   8.102 -  nl.m_groups |= buf[4];
   8.103 -  nl.m_groups <<= 8;
   8.104 -  nl.m_groups |= buf[5];
   8.105 -  nl.m_groups <<= 8;
   8.106 -  nl.m_groups |= buf[6];
   8.107 -  nl.m_groups <<= 8;
   8.108 -  nl.m_groups |= buf[7];
   8.109 -
   8.110 -  return nl;
   8.111 -}
   8.112 -
   8.113 -bool NetlinkSocketAddress::IsMatchingType (const Address &address)
   8.114 -{
   8.115 -  return address.IsMatchingType (GetType ());
   8.116 -}
   8.117 -
   8.118 -uint8_t NetlinkSocketAddress::GetType (void)
   8.119 -{
   8.120 -  static uint8_t type = Address::Register ();
   8.121 -  return type;
   8.122 -}
   8.123 -
   8.124 -} // namespace ns3
     9.1 --- a/model/netlink-socket-address.h	Tue Apr 19 23:13:50 2011 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,71 +0,0 @@
     9.4 -/* -*-	Mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     9.5 -/*
     9.6 - * Copyright (c) 2008 Liu Jian
     9.7 - *
     9.8 - * This program is free software; you can redistribute it and/or modify
     9.9 - * it under the terms of the GNU General Public License version 2 as
    9.10 - * published by the Free Software Foundation;
    9.11 - *
    9.12 - * This program is distributed in the hope that it will be useful,
    9.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.15 - * GNU General Public License for more details.
    9.16 - *
    9.17 - * You should have received a copy of the GNU General Public License
    9.18 - * along with this program; if not, write to the Free Software
    9.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.20 - *
    9.21 - * Author: Liu Jian <liujatp@gmail.com>
    9.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    9.23 - */
    9.24 -
    9.25 -#ifndef NETLINK_SOCKET_ADDRESS_H
    9.26 -#define NETLINK_SOCKET_ADDRESS_H
    9.27 -
    9.28 -#include "ns3/ptr.h"
    9.29 -#include "ns3/address.h"
    9.30 -
    9.31 -namespace ns3 {
    9.32 -
    9.33 -class NetlinkSocketAddress
    9.34 -{
    9.35 -public:
    9.36 -  NetlinkSocketAddress (uint32_t pid, uint32_t groups);
    9.37 -  NetlinkSocketAddress ();
    9.38 -  ~NetlinkSocketAddress ();
    9.39 -
    9.40 -  void SetProcessID (uint32_t pid);
    9.41 -  void SetGroupsMask (uint32_t mask);
    9.42 -
    9.43 -  uint32_t GetProcessID (void) const;
    9.44 -  uint32_t GetGroupsMask (void) const;
    9.45 -
    9.46 -  /**
    9.47 -  * \returns an Address instance which represents this
    9.48 -  * NetlinkSocketAddress instance.
    9.49 -  */
    9.50 -  operator Address (void) const;
    9.51 -  /**
    9.52 -  * \param address the Address instance to convert from.
    9.53 -  *
    9.54 -  * Returns an NetlinkSocketAddress which corresponds to the input
    9.55 -  * Address
    9.56 -  */
    9.57 -  static NetlinkSocketAddress ConvertFrom (const Address &address);
    9.58 -  /**
    9.59 -  * \returns true if the address matches, false otherwise.
    9.60 -  */
    9.61 -  static bool IsMatchingType (const Address &address);
    9.62 -private:
    9.63 -  static uint8_t GetType (void);
    9.64 -  Address ConvertTo (void) const;
    9.65 -
    9.66 -  uint32_t m_pid;
    9.67 -  uint32_t m_groups;
    9.68 -
    9.69 -};
    9.70 -
    9.71 -
    9.72 -} // namespace ns3
    9.73 -
    9.74 -#endif /* NETLINK_SOCKET_ADDRESS_H */
    10.1 --- a/model/netlink-socket-factory.cc	Tue Apr 19 23:13:50 2011 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,48 +0,0 @@
    10.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    10.5 -/*
    10.6 - * Copyright (c) 2008 Liu Jian
    10.7 - *
    10.8 - * This program is free software; you can redistribute it and/or modify
    10.9 - * it under the terms of the GNU General Public License version 2 as
   10.10 - * published by the Free Software Foundation;
   10.11 - *
   10.12 - * This program is distributed in the hope that it will be useful,
   10.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.15 - * GNU General Public License for more details.
   10.16 - *
   10.17 - * You should have received a copy of the GNU General Public License
   10.18 - * along with this program; if not, write to the Free Software
   10.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.20 - *
   10.21 - * Author: Liu Jian <liujatp@gmail.com>
   10.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   10.23 - */
   10.24 -
   10.25 -#include "netlink-socket-factory.h"
   10.26 -#include "netlink-socket.h"
   10.27 -#include "ns3/node.h"
   10.28 -
   10.29 -namespace ns3 {
   10.30 -
   10.31 -NS_OBJECT_ENSURE_REGISTERED (NetlinkSocketFactory);
   10.32 -
   10.33 -TypeId 
   10.34 -NetlinkSocketFactory::GetTypeId (void)
   10.35 -{
   10.36 -  static TypeId tid = TypeId ("ns3::NetlinkSocketFactory")
   10.37 -    .SetParent<SocketFactory> ();
   10.38 -  return tid;
   10.39 -}
   10.40 -
   10.41 -NetlinkSocketFactory::NetlinkSocketFactory ()
   10.42 -{}
   10.43 -
   10.44 -Ptr<Socket> NetlinkSocketFactory::CreateSocket (void)
   10.45 -{
   10.46 -  Ptr<Node> node = GetObject<Node> ();
   10.47 -  Ptr<NetlinkSocket> socket = CreateObject<NetlinkSocket> ();
   10.48 -  socket->SetNode (node);
   10.49 -  return socket;
   10.50 -} 
   10.51 -} // namespace ns3
    11.1 --- a/model/netlink-socket-factory.h	Tue Apr 19 23:13:50 2011 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,52 +0,0 @@
    11.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    11.5 -/*
    11.6 - * Copyright (c) 2008 Liu Jian
    11.7 - *
    11.8 - * This program is free software; you can redistribute it and/or modify
    11.9 - * it under the terms of the GNU General Public License version 2 as
   11.10 - * published by the Free Software Foundation;
   11.11 - *
   11.12 - * This program is distributed in the hope that it will be useful,
   11.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 - * GNU General Public License for more details.
   11.16 - *
   11.17 - * You should have received a copy of the GNU General Public License
   11.18 - * along with this program; if not, write to the Free Software
   11.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.20 - *
   11.21 - * Author: Liu Jian <liujatp@gmail.com>
   11.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   11.23 - */
   11.24 -
   11.25 -#ifndef NETLINK_SOCKET_FACTORY_H
   11.26 -#define NETLINK_SOCKET_FACTORY_H
   11.27 -
   11.28 -#include "ns3/socket-factory.h"
   11.29 -
   11.30 -namespace ns3 {
   11.31 -
   11.32 -class Socket;
   11.33 -
   11.34 -/**
   11.35 - * This can be used as an interface in a node in order for the node to
   11.36 - * generate NetlinkSockets.
   11.37 - */
   11.38 -class NetlinkSocketFactory : public SocketFactory
   11.39 -{
   11.40 -public:
   11.41 -  static TypeId GetTypeId (void);
   11.42 -
   11.43 -  NetlinkSocketFactory ();
   11.44 -
   11.45 -  /**
   11.46 -   * Creates a NetlinkSocket and returns a pointer to it.
   11.47 -   *
   11.48 -   * \return a pointer to the created socket
   11.49 -   */
   11.50 -  virtual Ptr<Socket> CreateSocket (void);
   11.51 -};
   11.52 -
   11.53 -} // namespace ns3
   11.54 -
   11.55 -#endif /* NETLINK_SOCKET_FACTORY_H */
    12.1 --- a/model/netlink-socket.cc	Tue Apr 19 23:13:50 2011 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,1571 +0,0 @@
    12.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    12.5 -/*
    12.6 - * Copyright (c) 2008 Liu Jian
    12.7 - *
    12.8 - * This program is free software; you can redistribute it and/or modify
    12.9 - * it under the terms of the GNU General Public License version 2 as
   12.10 - * published by the Free Software Foundation;
   12.11 - *
   12.12 - * This program is distributed in the hope that it will be useful,
   12.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 - * GNU General Public License for more details.
   12.16 - *
   12.17 - * You should have received a copy of the GNU General Public License
   12.18 - * along with this program; if not, write to the Free Software
   12.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.20 - *
   12.21 - * Author: Liu Jian <liujatp@gmail.com>
   12.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   12.23 - */
   12.24 -
   12.25 -#include "netlink-socket.h"
   12.26 -#include "netlink-socket-address.h"
   12.27 -#include "netlink-message.h"
   12.28 -#include "netlink-message-route.h"
   12.29 -#include "ns3/log.h"
   12.30 -#include "ns3/node.h"
   12.31 -#include "ns3/packet.h"
   12.32 -#include "ns3/ipv4-address.h"
   12.33 -#include "ns3/ipv4.h"
   12.34 -#include "ns3/simple-net-device.h"
   12.35 -#include "ns3/uinteger.h"
   12.36 -#include "ns3/trace-source-accessor.h"
   12.37 -#include <iostream>
   12.38 -#include <sstream>
   12.39 -#include "ns3/ipv6-address.h"
   12.40 -#include "ns3/ipv6.h"
   12.41 -#include "ns3/ipv4-l3-protocol.h"
   12.42 -#include "ns3/ipv4-static-routing-helper.h"
   12.43 -#include "ns3/ipv4-routing-table-entry.h"
   12.44 -#include "ns3/ipv6-l3-protocol.h"
   12.45 -#include "ns3/ipv6-interface.h"
   12.46 -#include "ns3/ipv6-static-routing-helper.h"
   12.47 -#include "ns3/ipv6-routing-table-entry.h"
   12.48 -#include "ns3/socket.h"
   12.49 -#include "ns3/mac48-address.h"
   12.50 -#include <sys/socket.h>
   12.51 -#include <linux/if.h>
   12.52 -#include <errno.h>
   12.53 -
   12.54 -NS_LOG_COMPONENT_DEFINE ("NetlinkSocket");
   12.55 -
   12.56 -namespace ns3 {
   12.57 -
   12.58 -// GroupSockets store the netlinksocket with noero group value
   12.59 -// it was due to the mulitcast netlink messages.
   12.60 -class GroupSockets
   12.61 -{
   12.62 -public:
   12.63 -  static uint32_t GetNSockets(void)
   12.64 -  { 
   12.65 -    return m_Sockets.size();
   12.66 -  }
   12.67 -  static Ptr<NetlinkSocket> GetSocket(uint32_t index)
   12.68 -  {
   12.69 -    NS_ASSERT(index < m_Sockets.size());
   12.70 -    return m_Sockets[index];
   12.71 -  }
   12.72 -  static void AddSocket(Ptr<NetlinkSocket>sock)
   12.73 -  {
   12.74 -    m_Sockets.push_back(sock);
   12.75 -  }
   12.76 -private:
   12.77 -   /*use a std::vector to store the sockets with nozero group value*/
   12.78 -  static std::vector<Ptr<NetlinkSocket> >m_Sockets;
   12.79 -};
   12.80 -std::vector<Ptr<NetlinkSocket> >GroupSockets::m_Sockets;
   12.81 -
   12.82 -NS_OBJECT_ENSURE_REGISTERED (NetlinkSocket);
   12.83 -
   12.84 -/*
   12.85 -Netlink Socket
   12.86 -*/
   12.87 -TypeId
   12.88 -NetlinkSocket::GetTypeId (void)
   12.89 -{
   12.90 -  static TypeId tid = TypeId ("ns3::NetlinkSocket")
   12.91 -    .SetParent<Socket> ()
   12.92 -    .AddConstructor<NetlinkSocket> ()
   12.93 -    .AddTraceSource ("Drop", "Drop packet due to receive buffer overflow",
   12.94 -                     MakeTraceSourceAccessor (&NetlinkSocket::m_dropTrace))
   12.95 -    .AddAttribute ("RcvBufSize",
   12.96 -                   "NetlinkSocket maximum receive buffer size (bytes)",
   12.97 -                   UintegerValue (0xffffffffl),
   12.98 -                   MakeUintegerAccessor (&NetlinkSocket::m_rcvBufSize),
   12.99 -                   MakeUintegerChecker<uint32_t> ())
  12.100 -    .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is received on this socket.",
  12.101 -                   CallbackValue (),
  12.102 -                   MakeCallbackAccessor (&NetlinkSocket::m_icmpCallback),
  12.103 -                   MakeCallbackChecker ())
  12.104 -    ;
  12.105 -  return tid;
  12.106 -}
  12.107 -
  12.108 -NetlinkSocket::NetlinkSocket ()
  12.109 -  : m_shutdownSend (false),
  12.110 -    m_shutdownRecv (false),
  12.111 -    m_rxAvailable (0),
  12.112 -    m_srcPid (0),
  12.113 -    m_srcGroups (0),
  12.114 -    m_dstPid (0),
  12.115 -    m_dstGroups (0)
  12.116 -{
  12.117 -  NS_LOG_FUNCTION_NOARGS ();
  12.118 -  m_errno = ERROR_NOTERROR;
  12.119 -}
  12.120 -NetlinkSocket::~NetlinkSocket ()
  12.121 -{
  12.122 -  NS_LOG_FUNCTION (this);
  12.123 -}
  12.124 -void 
  12.125 -NetlinkSocket::DoDispose (void)
  12.126 -{
  12.127 -  NS_LOG_FUNCTION_NOARGS ();
  12.128 -}
  12.129 -
  12.130 -int
  12.131 -NetlinkSocket::ErrnoToSimuErrno (void)
  12.132 -{
  12.133 -  switch (m_errno)
  12.134 -    {
  12.135 -    case Socket::ERROR_ISCONN:
  12.136 -      return EISCONN;
  12.137 -    case Socket::ERROR_NOTCONN:
  12.138 -      return ENOTCONN;
  12.139 -    case Socket::ERROR_MSGSIZE:
  12.140 -      return EMSGSIZE;
  12.141 -    case Socket::ERROR_AGAIN:
  12.142 -      return EAGAIN;
  12.143 -    case Socket::ERROR_SHUTDOWN:
  12.144 -      return ESHUTDOWN;
  12.145 -    case Socket::ERROR_OPNOTSUPP:
  12.146 -      return EOPNOTSUPP;
  12.147 -    case Socket::ERROR_AFNOSUPPORT:
  12.148 -      return EAFNOSUPPORT;
  12.149 -    case Socket::ERROR_INVAL:
  12.150 -      return EINVAL;
  12.151 -    case Socket::ERROR_BADF:
  12.152 -      return EBADF;
  12.153 -    case Socket::ERROR_NOROUTETOHOST:
  12.154 -      return EHOSTUNREACH;
  12.155 -    case Socket::ERROR_NODEV:
  12.156 -      return ENODEV;
  12.157 -    case Socket::ERROR_ADDRNOTAVAIL:
  12.158 -      return EADDRNOTAVAIL;
  12.159 -    case Socket::SOCKET_ERRNO_LAST:
  12.160 -    case Socket::ERROR_NOTERROR:
  12.161 -    default:
  12.162 -      NS_ASSERT (false);
  12.163 -      return 0; // quiet compiler
  12.164 -      break;
  12.165 -    }
  12.166 -}
  12.167 -
  12.168 -void 
  12.169 -NetlinkSocket::SetNode (Ptr<Node> node)
  12.170 -{
  12.171 -  NS_LOG_FUNCTION_NOARGS ();
  12.172 -  m_node = node;
  12.173 -}
  12.174 -
  12.175 -
  12.176 -enum Socket::SocketErrno
  12.177 -NetlinkSocket::GetErrno (void) const
  12.178 -{
  12.179 -  NS_LOG_FUNCTION_NOARGS ();
  12.180 -  return m_errno;
  12.181 -}
  12.182 -enum Socket::SocketType 
  12.183 -NetlinkSocket::GetSocketType (void) const
  12.184 -{
  12.185 -  return Socket::NS3_SOCK_DGRAM;
  12.186 -}
  12.187 -
  12.188 -Ptr<Node>
  12.189 -NetlinkSocket::GetNode (void) const
  12.190 -{
  12.191 -  NS_LOG_FUNCTION_NOARGS ();
  12.192 -  return m_node;
  12.193 -}
  12.194 -
  12.195 -uint32_t
  12.196 -NetlinkSocket::GetSrcPid (void) const
  12.197 -{
  12.198 -  NS_LOG_FUNCTION_NOARGS ();
  12.199 -  return m_srcPid;
  12.200 -}
  12.201 -uint32_t
  12.202 -NetlinkSocket::GetSrcGroups (void)const
  12.203 -{
  12.204 -  NS_LOG_FUNCTION_NOARGS ();
  12.205 -  return m_srcGroups;
  12.206 -}
  12.207 -uint32_t
  12.208 -NetlinkSocket::GetDstPid (void) const
  12.209 -{
  12.210 -  NS_LOG_FUNCTION_NOARGS ();
  12.211 -  return m_dstPid;
  12.212 -}
  12.213 -uint32_t
  12.214 -NetlinkSocket::GetDstGroups (void)const
  12.215 -{
  12.216 -  NS_LOG_FUNCTION_NOARGS ();
  12.217 -  return m_dstGroups;
  12.218 -}
  12.219 -
  12.220 -int
  12.221 -NetlinkSocket::Bind (void)
  12.222 -{
  12.223 -  NS_LOG_FUNCTION_NOARGS ();
  12.224 -  NetlinkSocketAddress address;
  12.225 -  return DoBind (address);
  12.226 -}
  12.227 -int
  12.228 -NetlinkSocket::Bind (const Address &address)
  12.229 -{ 
  12.230 -  NS_LOG_FUNCTION (this << address);
  12.231 -
  12.232 -  if (!NetlinkSocketAddress::IsMatchingType (address))
  12.233 -    {
  12.234 -      m_errno = ERROR_INVAL;
  12.235 -      return -1;
  12.236 -    }
  12.237 -  NetlinkSocketAddress ad = NetlinkSocketAddress::ConvertFrom (address);
  12.238 -  return DoBind (ad);
  12.239 -}
  12.240 -int
  12.241 -NetlinkSocket::DoBind (const NetlinkSocketAddress &address)
  12.242 -{
  12.243 -  NS_LOG_FUNCTION (this << address);
  12.244 -
  12.245 -  m_srcPid = address.GetProcessID ();
  12.246 -  m_srcGroups = address.GetGroupsMask ();
  12.247 -
  12.248 -  if (m_srcGroups)
  12.249 -    {
  12.250 -      GroupSockets::AddSocket(this);
  12.251 -    } 
  12.252 -  return 0;
  12.253 -}
  12.254 -
  12.255 -int 
  12.256 -NetlinkSocket::Listen (void)
  12.257 -{
  12.258 -  NS_LOG_FUNCTION_NOARGS ();
  12.259 -  m_errno = Socket::ERROR_OPNOTSUPP;
  12.260 -  return -1;
  12.261 -}
  12.262 -
  12.263 -uint32_t
  12.264 -NetlinkSocket::GetTxAvailable (void) const
  12.265 -{
  12.266 -  NS_LOG_FUNCTION_NOARGS ();
  12.267 -  return 0;
  12.268 -}
  12.269 -uint32_t
  12.270 -NetlinkSocket::GetRxAvailable (void) const
  12.271 -{
  12.272 -  NS_LOG_FUNCTION_NOARGS ();
  12.273 -  // We separately maintain this state to avoid walking the queue 
  12.274 -  // every time this might be called
  12.275 -  return m_rxAvailable;
  12.276 -}
  12.277 -
  12.278 -int
  12.279 -NetlinkSocket::ShutdownSend (void)
  12.280 -{
  12.281 -  NS_LOG_FUNCTION_NOARGS ();
  12.282 -  m_shutdownSend = true;
  12.283 -  return 0;
  12.284 -}
  12.285 -int
  12.286 -NetlinkSocket::ShutdownRecv (void)
  12.287 -{
  12.288 -  NS_LOG_FUNCTION_NOARGS ();
  12.289 -  m_shutdownRecv = true;
  12.290 -  return 0;
  12.291 -}
  12.292 -
  12.293 -int
  12.294 -NetlinkSocket::Close (void)
  12.295 -{
  12.296 -  NS_LOG_FUNCTION_NOARGS ();
  12.297 -  ShutdownSend();
  12.298 -  ShutdownRecv();
  12.299 -  return 0;
  12.300 -}
  12.301 -
  12.302 -int
  12.303 -NetlinkSocket::Connect (const Address &address)
  12.304 -{
  12.305 -  NS_LOG_FUNCTION (this << address);
  12.306 -  m_errno = Socket::ERROR_OPNOTSUPP;
  12.307 -  return 0;
  12.308 -}
  12.309 -
  12.310 -Ptr<Packet>
  12.311 -NetlinkSocket::Recv (uint32_t maxSize, uint32_t flags)
  12.312 -{
  12.313 -  NS_LOG_FUNCTION (this << maxSize<< flags);
  12.314 -  if (m_dataReceiveQueue.empty())
  12.315 -    {
  12.316 -      return 0;
  12.317 -    }
  12.318 -
  12.319 -  Ptr<Packet> p = m_dataReceiveQueue.front ();
  12.320 -  if (p->GetSize () <= maxSize) 
  12.321 -    {
  12.322 -      m_dataReceiveQueue.pop ();
  12.323 -      m_rxAvailable -= p->GetSize ();
  12.324 -    }
  12.325 -  else
  12.326 -    {
  12.327 -      p = 0; 
  12.328 -    }
  12.329 -  return p;
  12.330 -}
  12.331 -
  12.332 -Ptr<Packet>
  12.333 -NetlinkSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
  12.334 -{
  12.335 -  NS_LOG_FUNCTION (this << maxSize << flags << fromAddress);
  12.336 -  Ptr<Packet> packet = Recv (maxSize, flags);
  12.337 -  if (packet != 0)
  12.338 -    {
  12.339 -      SocketAddressTag tag;
  12.340 -      bool found;
  12.341 -      found = packet->FindFirstMatchingByteTag (tag);
  12.342 -      NS_ASSERT (found);
  12.343 -      fromAddress = tag.GetAddress ();
  12.344 -    }
  12.345 -  return packet;
  12.346 -}
  12.347 -
  12.348 -int
  12.349 -NetlinkSocket::Send (Ptr<Packet> p,uint32_t flags)
  12.350 -{
  12.351 -  NS_LOG_FUNCTION (this << p << flags);
  12.352 -  NetlinkSocketAddress address = NetlinkSocketAddress(m_dstPid, m_dstGroups);
  12.353 -  return SendTo(p, flags, address);
  12.354 -}
  12.355 -
  12.356 -int
  12.357 -NetlinkSocket::SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress)
  12.358 -{
  12.359 -  NS_LOG_FUNCTION (this << p << flags << toAddress);
  12.360 -  NetlinkSocketAddress ad;
  12.361 -
  12.362 -  if (!NetlinkSocketAddress::IsMatchingType (toAddress))
  12.363 -    {
  12.364 -      NS_LOG_LOGIC ("ERROR_AFNOSUPPORT");
  12.365 -      m_errno = ERROR_AFNOSUPPORT;
  12.366 -      return -1;
  12.367 -    }
  12.368 -  ad = NetlinkSocketAddress::ConvertFrom (toAddress);
  12.369 -  m_dstPid = ad.GetProcessID();
  12.370 -  m_dstGroups = ad.GetGroupsMask();
  12.371 -  NS_LOG_INFO ("send netlink message to pid = " << m_dstPid << ", groups = " << m_dstGroups);
  12.372 -  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending netlink message from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ());
  12.373 -
  12.374 -  //Ptr<NetlinkSocket>kernel_socket = GetNetlinkSocketByAddress(ad);
  12.375 -  //kernel_socket->m_receivedData.push_back(p);
  12.376 -  //kernel_socket->NotifyDataReceived(p);
  12.377 -
  12.378 -  //when netlink socket send packet, the first step is to find the dest netlink socket through address
  12.379 -  //then send the packet to it. For we partly implement the netlink-family, the dest address
  12.380 -  //is always the kernel(pid = 0), (Actually, there must be one static kernel netlink socket to
  12.381 -  //receive/handle messages), we do not setup a kernel socket to receive packet.
  12.382 -  //
  12.383 -  
  12.384 -  MultipartNetlinkMessage multipartnlmsg;
  12.385 -  uint32_t packet_len, remain_len;
  12.386 -
  12.387 -  packet_len = p->GetSize ();
  12.388 -  remain_len = packet_len;
  12.389 -
  12.390 -  while (remain_len > NetlinkMessageHeader::GetHeaderSize ())
  12.391 -    {
  12.392 -      remain_len -= p->RemoveHeader (multipartnlmsg);
  12.393 -      NS_ASSERT (remain_len == p->GetSize ());
  12.394 -
  12.395 -      //actually, message to kernel contains single one netlink message
  12.396 -      for (uint32_t i = 0; i < multipartnlmsg.GetNMessages(); i ++)
  12.397 -        {
  12.398 -          NetlinkMessage nlmsg = multipartnlmsg.GetMessage (i);
  12.399 -          if (HandleMessage (nlmsg) < 0)
  12.400 -            {
  12.401 -              if (m_errno)
  12.402 -                {
  12.403 -                  SendAckMessage (nlmsg, -ErrnoToSimuErrno ());
  12.404 -                }
  12.405 -            }
  12.406 -          else if (NetlinkMessage::IsMessageFlagsAck (nlmsg.GetHeader ().GetMsgFlags ()))
  12.407 -            {
  12.408 -              SendAckMessage (nlmsg, 0);
  12.409 -            }
  12.410 -        }
  12.411 -    }
  12.412 -
  12.413 -  NotifyDataSent (packet_len);
  12.414 -  NS_LOG_INFO ("netlink socket kernel error " << -m_errno);
  12.415 -  return packet_len;
  12.416 -}
  12.417 -
  12.418 -int
  12.419 -NetlinkSocket::GetSockName (Address &address) const
  12.420 -{
  12.421 -  NS_LOG_FUNCTION_NOARGS ();
  12.422 -  NetlinkSocketAddress ad;
  12.423 -
  12.424 -  ad.SetProcessID (GetSrcPid ());
  12.425 -  ad.SetGroupsMask (GetSrcGroups ());
  12.426 -  address = ad;
  12.427 -  return 0;
  12.428 -}
  12.429 -int
  12.430 -NetlinkSocket::GetPeerName (Address &address) const
  12.431 -{
  12.432 -  NS_LOG_FUNCTION_NOARGS ();
  12.433 -  // XXX
  12.434 -  NS_ASSERT (false);
  12.435 -  return -1;
  12.436 -}
  12.437 -bool 
  12.438 -NetlinkSocket::SetAllowBroadcast (bool allowBroadcast)
  12.439 -{
  12.440 -  NS_ASSERT (false);
  12.441 -  return false;
  12.442 -}
  12.443 -bool 
  12.444 -NetlinkSocket::GetAllowBroadcast () const
  12.445 -{
  12.446 -  NS_ASSERT (false);
  12.447 -  return false;
  12.448 -}
  12.449 -
  12.450 -
  12.451 -void
  12.452 -NetlinkSocket::ForwardUp (Ptr<Packet> packet, NetlinkSocketAddress &address)
  12.453 -{
  12.454 -  NS_LOG_FUNCTION (this << packet << address);
  12.455 -
  12.456 -  if (m_shutdownRecv)
  12.457 -    {
  12.458 -      return;
  12.459 -    }
  12.460 -  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
  12.461 -    {
  12.462 -      SocketAddressTag tag;
  12.463 -      tag.SetAddress (address);
  12.464 -      packet->AddByteTag (tag);
  12.465 -      m_dataReceiveQueue.push (packet);
  12.466 -      m_rxAvailable += packet->GetSize ();
  12.467 -      NotifyDataRecv ();
  12.468 -    }
  12.469 -  else
  12.470 -    {
  12.471 -      NS_LOG_WARN ("No receive buffer space available.  Drop.");
  12.472 -      m_dropTrace (packet);
  12.473 -    }
  12.474 -}
  12.475 -
  12.476 -int32_t
  12.477 -NetlinkSocket::SendMessageUnicast (const MultipartNetlinkMessage &nlmsg, uint32_t pid, int32_t nonblock)
  12.478 -{
  12.479 -  NS_LOG_FUNCTION (this << pid << nonblock);
  12.480 -  //here we send message instantly
  12.481 -  Ptr<Packet> p = Create<Packet> ();
  12.482 -  p->AddHeader (nlmsg);
  12.483 -
  12.484 -  NetlinkSocketAddress address;
  12.485 -  address.SetProcessID (pid);
  12.486 -
  12.487 -  //send packet to user space
  12.488 -  ForwardUp (p, address);
  12.489 -  return 0;
  12.490 -}
  12.491 -int32_t
  12.492 -NetlinkSocket::SendMessageBroadcast (const MultipartNetlinkMessage &nlmsg, 
  12.493 -                                     uint32_t pid, 
  12.494 -                                     uint32_t group,
  12.495 -                                     Ptr<Node> node)
  12.496 -{
  12.497 -  NS_LOG_FUNCTION ("SendMessageBroadcast" << pid << group);
  12.498 -  //fisrt find the dest netlink socket through group value, then attach this nlmsg to its recv-queue
  12.499 -  for (uint32_t i = 0; i < GroupSockets::GetNSockets (); i ++)
  12.500 -    {
  12.501 -      Ptr<NetlinkSocket> nlsock = GroupSockets::GetSocket (i);
  12.502 -
  12.503 -      if ((nlsock->GetSrcGroups () & group) &&
  12.504 -          (nlsock->GetSrcPid () != pid) &&
  12.505 -          node == nlsock->GetNode ())
  12.506 -        {
  12.507 -          //here we send message instantly
  12.508 -          Ptr<Packet> p = Create<Packet> ();
  12.509 -          p->AddHeader (nlmsg);
  12.510 -
  12.511 -          NetlinkSocketAddress address;
  12.512 -          address.SetProcessID (nlsock->GetSrcPid());
  12.513 -          address.SetGroupsMask (group);
  12.514 -
  12.515 -          //send packet to user space
  12.516 -          nlsock->ForwardUp (p, address);
  12.517 -        }
  12.518 -    }
  12.519 -  return 0;
  12.520 -}
  12.521 -void
  12.522 -NetlinkSocket::SendAckMessage (const NetlinkMessage&nlmsg, int32_t err)
  12.523 -{
  12.524 -  NS_LOG_FUNCTION (this << err);
  12.525 -  NetlinkMessageHeader rep;
  12.526 -  NetlinkMessage ackmsg;
  12.527 -  NetlinkMessageError errmsg;
  12.528 -
  12.529 -  rep.SetMsgPid (nlmsg.GetHeader ().GetMsgPid ());
  12.530 -  rep.SetMsgSeq (nlmsg.GetHeader ().GetMsgSeq ());
  12.531 -  rep.SetMsgType (NETLINK_MSG_ERROR);
  12.532 -  rep.SetMsgFlags (0);
  12.533 -
  12.534 -  errmsg.SetError (err);
  12.535 -  //kernel send the whole nlmsg back if error != 0, here we just send the header back
  12.536 -  errmsg.SetMsg (nlmsg.GetHeader ());
  12.537 -
  12.538 -  //then send errmsg back to user space
  12.539 -  ackmsg.SetHeader (rep);
  12.540 -  ackmsg.SetErrorMessage (errmsg);
  12.541 -
  12.542 -  SendMessageUnicast (ackmsg, rep.GetMsgPid (), 1);
  12.543 -}
  12.544 -
  12.545 -int32_t
  12.546 -NetlinkSocket::HandleMessage (const NetlinkMessage&nlmsg)
  12.547 -{
  12.548 -  NS_LOG_FUNCTION (this);
  12.549 -  uint16_t type = nlmsg.GetMsgType ();
  12.550 -  NetlinkMessageHeader nhr = nlmsg.GetHeader ();
  12.551 -
  12.552 -  if (nhr.GetMsgLen () < NetlinkMessageHeader::GetHeaderSize ())
  12.553 -    {
  12.554 -      m_errno = ERROR_INVAL;
  12.555 -      return -1;
  12.556 -    }
  12.557 -
  12.558 -  if (NetlinkMessage::IsMessageNetlinkControl (type))
  12.559 -    {
  12.560 -      NS_LOG_INFO ("netlink control message type not parsed in kernel");
  12.561 -      return 0;
  12.562 -    }
  12.563 -  else if (NetlinkMessage::IsMessageNetlinkRoute (type))
  12.564 -    {
  12.565 -      return HandleNetlinkRouteMessage (nlmsg);
  12.566 -    }
  12.567 -  else
  12.568 -    {
  12.569 -      NS_LOG_INFO ("netlink message type not parsed in kernel");
  12.570 -      m_errno = ERROR_INVAL;
  12.571 -      return -1;
  12.572 -    }  
  12.573 -}
  12.574 -
  12.575 -int32_t
  12.576 -NetlinkSocket::HandleNetlinkRouteMessage (const NetlinkMessage &nlmsg)
  12.577 -{
  12.578 -  NS_LOG_FUNCTION (this);
  12.579 -  uint8_t family;
  12.580 -  int16_t type;
  12.581 -  int32_t err;
  12.582 -
  12.583 -  /* Only requests are handled by kernel now */
  12.584 -  if (!NetlinkMessage::IsMessageFlagsRequest (nlmsg.GetHeader ().GetMsgFlags ()))
  12.585 -    return 0;
  12.586 -
  12.587 -  type = nlmsg.GetMsgType ();
  12.588 -
  12.589 -  /* A control message: ignore them */
  12.590 -  if (NetlinkMessage::IsMessageNetlinkControl (type))
  12.591 -    {
  12.592 -      return 0;
  12.593 -    }
  12.594 -  else if (NetlinkMessage::IsMessageNetlinkRoute (type))
  12.595 -    {
  12.596 -      /* All the messages must have at least 1 byte length */
  12.597 -      if (nlmsg.GetPayloadSize () < 1)
  12.598 -        return 0;
  12.599 -
  12.600 -      family = nlmsg.GetFamily ();
  12.601 -      /*here we do not deal with different family, default for AF_NET*/
  12.602 -      NS_ASSERT(family == AF_INET || family == AF_UNSPEC || family == AF_PACKET || family == AF_INET6);  
  12.603 -
  12.604 -      /*for GET*** message, dump it to userspace*/
  12.605 -      if (NetlinkMessage::IsMessageTypeGet (type) && 
  12.606 -          NetlinkMessage::IsMessageFlagsDump (nlmsg.GetHeader ().GetMsgFlags ())) 
  12.607 -        {
  12.608 -          DumpNetlinkRouteMessage (nlmsg, type, family);
  12.609 -          return -1;
  12.610 -        }
  12.611 -
  12.612 -      /* other types of messages*/
  12.613 -      return DoNetlinkRouteMessage (nlmsg, type, family);
  12.614 -    }
  12.615 -  else/* Unknown message: reply with EINVAL */
  12.616 -    {
  12.617 -      err = ERROR_INVAL;
  12.618 -      return -1;
  12.619 -    } 
  12.620 -}
  12.621 -
  12.622 -int32_t
  12.623 -NetlinkSocket::DumpNetlinkRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  12.624 -{
  12.625 -  NS_LOG_FUNCTION (this << type << family);
  12.626 -
  12.627 -  NS_ASSERT (type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETLINK);
  12.628 -
  12.629 -  MultipartNetlinkMessage nlmsg_dump;
  12.630 -  NetlinkMessageHeader nhr = nlmsg.GetHeader ();
  12.631 -  int32_t err;
  12.632 -
  12.633 -  if (type == NETLINK_RTM_GETADDR)
  12.634 -    {
  12.635 -      nlmsg_dump = BuildInterfaceAddressDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);
  12.636 -    }
  12.637 -  else if (type == NETLINK_RTM_GETLINK)
  12.638 -    {
  12.639 -      nlmsg_dump = BuildInterfaceInfoDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);      
  12.640 -    }
  12.641 -  else if (type == NETLINK_RTM_GETROUTE)
  12.642 -    {
  12.643 -      nlmsg_dump = BuildRouteDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);
  12.644 -    }
  12.645 -  else
  12.646 -    {
  12.647 -      m_errno = ERROR_INVAL;
  12.648 -      return -1;
  12.649 -    }
  12.650 -
  12.651 -  //then append netlink message with type NLMSG_DONE
  12.652 -  NetlinkMessage nlmsg_done;
  12.653 -  NetlinkMessageHeader nhr2 = NetlinkMessageHeader (NETLINK_MSG_DONE, NETLINK_MSG_F_MULTI, 
  12.654 -                                                   nlmsg.GetHeader ().GetMsgSeq (), m_srcPid);
  12.655 -  nlmsg_done.SetHeader (nhr2);
  12.656 -  //kernel append nlmsg_dump size to it, here we omit it
  12.657 -  nlmsg_dump.AppendMessage (nlmsg_done);
  12.658 -
  12.659 -  err = SendMessageUnicast (nlmsg_dump, m_srcPid, 1);
  12.660 -  return err;
  12.661 -}
  12.662 -
  12.663 -/*here only for ADD/DEL/GET*** types*/
  12.664 -int32_t
  12.665 -NetlinkSocket::DoNetlinkRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  12.666 -{
  12.667 -  NS_LOG_FUNCTION (this << type <<family);
  12.668 -  int32_t err;
  12.669 -
  12.670 -  if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  12.671 -    {      
  12.672 -      err = DoInterfaceAddressMessage (nlmsg, type, family);
  12.673 -    }
  12.674 -  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  12.675 -    {     
  12.676 -      err = DoRouteMessage (nlmsg, type, family);
  12.677 -    }
  12.678 -  else if (type == NETLINK_RTM_GETLINK || type == NETLINK_RTM_SETLINK)
  12.679 -    {     
  12.680 -      err = DoInterfaceInfoMessage (nlmsg, type, family);
  12.681 -    }
  12.682 -  else
  12.683 -    {
  12.684 -      NS_LOG_LOGIC ("netlink message:type( " << type << ") not processed by ns3 now." );
  12.685 -      m_errno = ERROR_INVAL;
  12.686 -      err = -1;
  12.687 -    } 
  12.688 -  
  12.689 -  return err;
  12.690 -}
  12.691 -
  12.692 -MultipartNetlinkMessage
  12.693 -NetlinkSocket::BuildInterfaceAddressDumpMessage (uint32_t pid, uint32_t seq, uint8_t family)
  12.694 -{
  12.695 -  NS_LOG_FUNCTION (this << pid << seq <<family);
  12.696 -  MultipartNetlinkMessage nlmsg_dump;
  12.697 -  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
  12.698 -
  12.699 -  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++)
  12.700 -    {
  12.701 -      if (!ipv4->IsUp (i))
  12.702 -        continue;
  12.703 -
  12.704 -      Ipv4Address addri = ipv4->GetAddress (i, 0).GetLocal ();
  12.705 -      Ipv4Mask maski = ipv4->GetAddress (i, 0).GetMask ();
  12.706 -      Ipv4Address bcast = ipv4->GetAddress (i, 0).GetBroadcast ();
  12.707 -
  12.708 -      //here get the address mask length
  12.709 -      uint32_t mask = maski.Get ();
  12.710 -      uint8_t mask_len = 0;
  12.711 -      while (mask)
  12.712 -        {
  12.713 -          mask = mask << 1;
  12.714 -          mask_len ++;
  12.715 -        }
  12.716 -      
  12.717 -      //next fill the message body
  12.718 -      NetlinkMessage nlmsg_ifa;
  12.719 -      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWADDR, NETLINK_MSG_F_MULTI, seq, pid);
  12.720 -      InterfaceAddressMessage ifamsg;
  12.721 -
  12.722 -      ifamsg.SetInterfaceIndex (i);
  12.723 -      ifamsg.SetFamily (AF_INET);//default AF_INET      
  12.724 -      ifamsg.SetLength (mask_len);
  12.725 -      ifamsg.SetFlags (0);
  12.726 -      ifamsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  12.727 -
  12.728 -      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LOCAL,    ADDRESS, addri));
  12.729 -      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ADDRESS,  ADDRESS, addri));
  12.730 -      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_BROADCAST,ADDRESS, bcast));
  12.731 -      //      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LABEL,    STRING,  "ns3-ifaddr"));//not used in ns3
  12.732 -      //ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ANYCAST,  ADDRESS, Ipv4Address("0.0.0.0")));//not used in ns3
  12.733 -      //XXXother attributes not used by ns3
  12.734 -
  12.735 -      nlmsg_ifa.SetHeader(nhr);
  12.736 -      nlmsg_ifa.SetInterfaceAddressMessage (ifamsg);
  12.737 -      nlmsg_dump.AppendMessage (nlmsg_ifa);
  12.738 -    }
  12.739 -
  12.740 -  // For IPv6
  12.741 -  Ptr<Ipv6>ipv6 = m_node->GetObject<Ipv6> ();
  12.742 -
  12.743 -  for (uint32_t i = 0; i < ipv6->GetNInterfaces(); i ++)
  12.744 -    {
  12.745 -      if (!ipv6->IsUp (i))
  12.746 -        continue;
  12.747 -
  12.748 -      for (uint32_t j = 0; j < ipv6->GetNAddresses(i); j ++)
  12.749 -        {
  12.750 -          Ipv6Address addri = ipv6->GetAddress (i, j).GetAddress();
  12.751 -          Ipv6Prefix prefix = ipv6->GetAddress (i, j).GetPrefix ();
  12.752 -
  12.753 -          //here get the address mask length
  12.754 -          uint8_t mask_len = prefix.GetPrefixLength();
  12.755 -
  12.756 -          //loopback address's prefix is wrong... FIXME
  12.757 -          if (addri.IsEqual(Ipv6Address::GetLoopback()))
  12.758 -            mask_len = 128;
  12.759 -      
  12.760 -          //next fill the message body
  12.761 -          NetlinkMessage nlmsg_ifa;
  12.762 -          NetlinkMessageHeader nhr = NetlinkMessageHeader(NETLINK_RTM_NEWADDR, NETLINK_MSG_F_MULTI, seq, pid);
  12.763 -          InterfaceAddressMessage ifamsg;       
  12.764 -
  12.765 -          ifamsg.SetInterfaceIndex(i);
  12.766 -          ifamsg.SetFamily(AF_INET6);
  12.767 -          ifamsg.SetFlags(0);
  12.768 -
  12.769 -
  12.770 -          if (addri.IsLinkLocal())
  12.771 -            {
  12.772 -              ifamsg.SetLength(64);
  12.773 -              ifamsg.SetScope (RouteMessage::RT_SCOPE_LINK);
  12.774 -            }
  12.775 -          else
  12.776 -            {
  12.777 -              ifamsg.SetLength(mask_len);
  12.778 -              ifamsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  12.779 -            }
  12.780 -
  12.781 -
  12.782 -          ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LOCAL,    ADDRESS, addri));
  12.783 -          ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ADDRESS,  ADDRESS, addri));
  12.784 -          //XXXother attributes not used by ns3
  12.785 -
  12.786 -          nlmsg_ifa.SetHeader(nhr);
  12.787 -          nlmsg_ifa.SetInterfaceAddressMessage (ifamsg);
  12.788 -          nlmsg_dump.AppendMessage (nlmsg_ifa);
  12.789 -        }
  12.790 -    }
  12.791 -  return nlmsg_dump;
  12.792 -}
  12.793 -MultipartNetlinkMessage
  12.794 -NetlinkSocket::BuildInterfaceInfoDumpMessage (uint32_t pid, uint32_t seq, uint8_t family)
  12.795 -{
  12.796 -  NS_LOG_FUNCTION (this << pid << seq <<family);
  12.797 -  MultipartNetlinkMessage nlmsg_dump;
  12.798 -  for (uint32_t i = 0; i < m_node->GetNDevices (); i ++)
  12.799 -    {
  12.800 -      Ptr<NetDevice> dev = m_node->GetDevice (i);
  12.801 -      Address mac;
  12.802 -      Address bcast;
  12.803 -      uint32_t mtu;
  12.804 -      uint32_t flags = 0;
  12.805 -
  12.806 -      mac = dev->GetAddress ();
  12.807 -      bcast = dev->GetBroadcast ();
  12.808 -      mtu = (uint32_t)dev->GetMtu ();
  12.809 -
  12.810 -      if (dev->IsLinkUp ())
  12.811 -        {
  12.812 -          flags |= IFF_RUNNING;
  12.813 -          flags |= IFF_UP;
  12.814 -        }
  12.815 -      if (dev->IsBroadcast ())
  12.816 -        {
  12.817 -          flags |= IFF_BROADCAST;
  12.818 -        }
  12.819 -      if (dev->IsMulticast ())
  12.820 -        {
  12.821 -          flags |= IFF_MULTICAST;
  12.822 -        }
  12.823 -
  12.824 -      NetlinkMessage nlmsg_ifinfo;
  12.825 -      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWLINK, NETLINK_MSG_F_MULTI, seq, pid);
  12.826 -      InterfaceInfoMessage ifinfomsg;     
  12.827 -
  12.828 -      ifinfomsg.SetFamily(0);      // AF_UNSPEC
  12.829 -      ifinfomsg.SetDeviceType (0); // not clear
  12.830 -      ifinfomsg.SetInterfaceIndex (i);
  12.831 -      ifinfomsg.SetDeviceFlags (flags); // not clear
  12.832 -      ifinfomsg.SetChangeMask (0xffffffff);
  12.833 -
  12.834 -      // the ns3 device have no  name, here we set "ns3-device i" for test
  12.835 -      std::stringstream ss;
  12.836 -      ss <<  "ns3-device" << i;
  12.837 -
  12.838 -      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_IFNAME,    STRING,  ss.str()));
  12.839 -      //not used in ns3
  12.840 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_TXQLEN,    U32,     0));
  12.841 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_WEIGHT,    U32,     0));
  12.842 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_OPERSTATE, U8,      0));
  12.843 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_LINKMODE,  U8,      0));
  12.844 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_MAP,       UNSPEC,  0));
  12.845 -      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_ADDRESS,   ADDRESS, mac));
  12.846 -      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_BROADCAST, ADDRESS, bcast));
  12.847 -      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_MTU,       U32,     mtu));
  12.848 -      ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_LINK,      U32,     i));
  12.849 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_QDISC,     STRING,  ""));
  12.850 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_MASTER,    U32,     0));
  12.851 -      //ifinfomsg.AppendAttribute (NetlinkAttribute (InterfaceInfoMessage::IFL_A_STATS,     UNSPEC,  0));
  12.852 -
  12.853 -      nlmsg_ifinfo.SetHeader (nhr);
  12.854 -      nlmsg_ifinfo.SetInterfaceInfoMessage (ifinfomsg);
  12.855 -      nlmsg_dump.AppendMessage (nlmsg_ifinfo);
  12.856 -    }
  12.857 -  return nlmsg_dump;
  12.858 -}
  12.859 -MultipartNetlinkMessage
  12.860 -NetlinkSocket::BuildRouteDumpMessage (uint32_t pid, uint32_t seq, uint8_t family)
  12.861 -{
  12.862 -  NS_LOG_FUNCTION (this << pid << seq <<family);
  12.863 -  MultipartNetlinkMessage nlmsg_dump;
  12.864 -  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
  12.865 -
  12.866 -  // We only care about staticRouting for netlink support
  12.867 -  Ipv4StaticRoutingHelper routingHelper;
  12.868 -  Ptr<Ipv4StaticRouting> ipv4Static = routingHelper.GetStaticRouting (ipv4);
  12.869 -  for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); i ++)
  12.870 -    {
  12.871 -      NetlinkMessage nlmsg_rt;
  12.872 -      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, NETLINK_MSG_F_MULTI, seq, pid);
  12.873 -      RouteMessage rtmsg;
  12.874 -      Ipv4RoutingTableEntry route = ipv4Static->GetRoute (i);
  12.875 -
  12.876 -      rtmsg.SetFamily (AF_INET);
  12.877 -      rtmsg.SetDstLength (32);
  12.878 -      rtmsg.SetSrcLength (0);
  12.879 -      rtmsg.SetTos (0);//not clear
  12.880 -      rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
  12.881 -      rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  12.882 -      rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
  12.883 -      rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
  12.884 -
  12.885 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
  12.886 -      // ns3 use local address as the route src address
  12.887 -      //      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, route.GetSource()));
  12.888 -      //      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, route.GetSource()));//not used in ns3
  12.889 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface ()));
  12.890 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface ()));      
  12.891 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway ()));
  12.892 -
  12.893 -      nlmsg_rt.SetHeader (nhr);
  12.894 -      nlmsg_rt.SetRouteMessage (rtmsg);
  12.895 -      nlmsg_dump.AppendMessage (nlmsg_rt);
  12.896 -    }
  12.897 -
  12.898 -  Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
  12.899 -  // We only care about staticRouting for netlink support
  12.900 -  Ipv6StaticRoutingHelper routingHelper6;
  12.901 -  Ptr<Ipv6StaticRouting> ipv6Static = routingHelper6.GetStaticRouting (ipv6);
  12.902 -  for (uint32_t i = 0; i < ipv6Static->GetNRoutes (); i ++)
  12.903 -    {
  12.904 -      NetlinkMessage nlmsg_rt;
  12.905 -      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, NETLINK_MSG_F_MULTI, seq, pid);
  12.906 -      RouteMessage rtmsg;
  12.907 -      Ipv6RoutingTableEntry route = ipv6Static->GetRoute (i);
  12.908 -
  12.909 -      rtmsg.SetFamily (AF_INET6);
  12.910 -      rtmsg.SetDstLength (128);
  12.911 -      rtmsg.SetSrcLength (0);
  12.912 -      rtmsg.SetTos (0);//not clear
  12.913 -      rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
  12.914 -      rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
  12.915 -      rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
  12.916 -      rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
  12.917 -
  12.918 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
  12.919 -      //ns3 use local address as the route src address
  12.920 -      // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, 
  12.921 -      //                                          ipv6->GetSourceAddress(route.GetDest ())));
  12.922 -      // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, 
  12.923 -      //                                          ipv6->GetSourceAddress(route.GetDest ())));
  12.924 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface()));
  12.925 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface()));      
  12.926 -      rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway()));
  12.927 -
  12.928 -      nlmsg_rt.SetHeader (nhr);
  12.929 -      nlmsg_rt.SetRouteMessage (rtmsg);
  12.930 -      nlmsg_dump.AppendMessage (nlmsg_rt);
  12.931 -    }
  12.932 -
  12.933 -  return nlmsg_dump;
  12.934 -}
  12.935 -
  12.936 -int32_t
  12.937 -NetlinkSocket::DoInterfaceAddressMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  12.938 -{
  12.939 -  NS_LOG_FUNCTION (this << type << family);
  12.940 -  NS_ASSERT (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR);
  12.941 -
  12.942 -  // XXX
  12.943 -  NS_ASSERT_MSG (false, "Not implemented yet (RTM_NEWADDR/RTM_DELADDR)");
  12.944 -
  12.945 -  InterfaceAddressMessage ifamsg = nlmsg.GetInterfaceAddressMessage ();
  12.946 -  Ipv4Address addri, addr_local, bcast;
  12.947 -  NetlinkAttribute attr_local;
  12.948 -  uint32_t index = ifamsg.GetInterfaceIndex ();
  12.949 -  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
  12.950 -  int flag4 = 0, flag6 = 0;
  12.951 -
  12.952 -  if (type == NETLINK_RTM_NEWADDR)
  12.953 -    {
  12.954 -      //when adding an interface address, it should check the input arguments
  12.955 -      //prefix-len and local address attribute
  12.956 -      if (ifamsg.GetLength () > 32 || 
  12.957 -          ifamsg.GetAttributeByType (attr_local, InterfaceAddressMessage::IF_A_LOCAL) == false)
  12.958 -        {
  12.959 -          m_errno = ERROR_INVAL;
  12.960 -          return -1;
  12.961 -        }
  12.962 -    }  
  12.963 -
  12.964 -  //get necessary information for add/del, many attributes we not used
  12.965 -  for (uint32_t i = 0; i < ifamsg.GetNNetlinkAttribute (); i ++)
  12.966 -    {
  12.967 -      NetlinkAttribute attr = ifamsg.GetNetlinkAttribute (i);
  12.968 -      uint32_t attr_type = attr.GetAttrType ();
  12.969 -
  12.970 -      switch(attr_type)
  12.971 -        {
  12.972 -        case InterfaceAddressMessage::IF_A_ADDRESS:
  12.973 -          addri = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
  12.974 -          break;
  12.975 -        case InterfaceAddressMessage::IF_A_BROADCAST:
  12.976 -          bcast = Ipv4Address::ConvertFrom(attr.GetAttrPayload ().GetAddress ());
  12.977 -          break;
  12.978 -        case InterfaceAddressMessage::IF_A_LOCAL:
  12.979 -          addr_local = Ipv4Address::ConvertFrom(attr.GetAttrPayload ().GetAddress ());
  12.980 -          break;
  12.981 -        case InterfaceAddressMessage::IF_A_LABEL:
  12.982 -        case InterfaceAddressMessage::IF_A_ANYCAST:
  12.983 -          break;
  12.984 -        }
  12.985 -    }
  12.986 -
  12.987 -  if (type == NETLINK_RTM_NEWADDR)
  12.988 -    {
  12.989 -      //when adding an interface address by index, if the indexed interface was not exist,
  12.990 -      //create an new NetDevice with an new index and set the address
  12.991 -      //otherwise set the indexed interface directly
  12.992 -      if (index >= ipv4->GetNInterfaces ())
  12.993 -        {          
  12.994 -          Ptr<SimpleNetDevice> dev;
  12.995 -          dev = CreateObject<SimpleNetDevice> ();
  12.996 -          dev ->SetAddress (Mac48Address::Allocate ());
  12.997 -          m_node->AddDevice (dev);
  12.998 -
  12.999 -          uint32_t netdev_idx = ipv4->AddInterface (dev);
 12.1000 -          // FIXME!
 12.1001 -          Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (addri, Ipv4Mask ());
 12.1002 -          ipv4->AddAddress (netdev_idx, ipv4Addr);
 12.1003 -          ipv4->SetUp (netdev_idx);
 12.1004 -          NS_LOG_INFO ("Add an interface address at index "<< netdev_idx << "but not the ifamsg input" << index);
 12.1005 -        }
 12.1006 -      else
 12.1007 -        {
 12.1008 -          Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (addri, Ipv4Mask ());
 12.1009 -          ipv4->AddAddress (index, ipv4Addr);
 12.1010 -          if (!ipv4->IsUp (index))
 12.1011 -            ipv4->SetUp (index);
 12.1012 -        }    
 12.1013 -      flag4 = 1;
 12.1014 -    }
 12.1015 -  else//type == NETLINK_RTM_DELADDR
 12.1016 -    {
 12.1017 -      //when delete an interface address by index, if the indexed interface  was not exist
 12.1018 -      //return an error EINVAL, otherwise set down the interface which has the addri
 12.1019 -      if (index >= ipv4->GetNInterfaces ())
 12.1020 -        {
 12.1021 -          m_errno = ERROR_NODEV;
 12.1022 -          return -1;
 12.1023 -        }
 12.1024 -      else
 12.1025 -        {
 12.1026 -          for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++)
 12.1027 -            {
 12.1028 -              Ipv4Address ad = ipv4->GetAddress (i, 0).GetLocal ();
 12.1029 -              if (ad == addri && ipv4->IsUp (i))
 12.1030 -                {
 12.1031 -                  ipv4->SetDown (i);
 12.1032 -                  break;
 12.1033 -                }
 12.1034 -              if (i == ipv4->GetNInterfaces () - 1)
 12.1035 -                {
 12.1036 -                  m_errno = ERROR_ADDRNOTAVAIL;
 12.1037 -                  return -1;
 12.1038 -                }
 12.1039 -            }
 12.1040 -          flag4 = 1;
 12.1041 -        }      
 12.1042 -    }
 12.1043 -  
 12.1044 -  //then send an broadcast message, let all user know this operation happened
 12.1045 -  NetlinkMessage nlmsg_broadcast = nlmsg;
 12.1046 -  NetlinkMessageHeader nhr;
 12.1047 -  nhr.SetMsgLen (nlmsg.GetHeader ().GetMsgLen ());
 12.1048 -  nhr.SetMsgType (nlmsg.GetHeader ().GetMsgType ());
 12.1049 -  nlmsg_broadcast.SetHeader (nhr);
 12.1050 -  if (flag4)
 12.1051 -    {
 12.1052 -      SendMessageBroadcast (nlmsg_broadcast, 0, NETLINK_RTM_GRP_IPV4_IFADDR, GetNode ());
 12.1053 -    }
 12.1054 -  else if (flag6)
 12.1055 -    {
 12.1056 -      SendMessageBroadcast (nlmsg_broadcast, 0, RTMGRP_IPV6_IFADDR, GetNode ());
 12.1057 -    }
 12.1058 -
 12.1059 -  return 0;
 12.1060 -}
 12.1061 -
 12.1062 -int32_t
 12.1063 -NetlinkSocket::DoInterfaceInfoMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
 12.1064 -{
 12.1065 -  NS_LOG_FUNCTION (this << type << family);
 12.1066 -  NS_ASSERT (type == NETLINK_RTM_GETLINK || type == NETLINK_RTM_SETLINK);
 12.1067 -  InterfaceInfoMessage ifinfomsg = nlmsg.GetInterfaceInfoMessage ();
 12.1068 -  // XXX
 12.1069 -  NS_ASSERT_MSG (false, "Not implemented yet (RTM_GETLINK/RTM_SETLINK)");
 12.1070 -  return -1;
 12.1071 -}
 12.1072 -
 12.1073 -Address
 12.1074 -NetlinkSocket::ConvertFrom (uint8_t family, const Address &address)
 12.1075 -{
 12.1076 -  Address retval;
 12.1077 -  if (family == AF_INET)
 12.1078 -    {
 12.1079 -      retval = Ipv4Address::ConvertFrom (address);
 12.1080 -    }
 12.1081 -  else if (family == AF_INET6)
 12.1082 -    {
 12.1083 -      retval = Ipv6Address::ConvertFrom (address);
 12.1084 -    }
 12.1085 -  return retval;
 12.1086 -}
 12.1087 -
 12.1088 -int32_t
 12.1089 -NetlinkSocket::DoRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
 12.1090 -{
 12.1091 -  NS_LOG_FUNCTION (this << type << family);
 12.1092 -  NS_ASSERT (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE ||type == NETLINK_RTM_GETROUTE);
 12.1093 -
 12.1094 -  RouteMessage rtmsg = nlmsg.GetRouteMessage ();
 12.1095 -  Ipv4Address src, dest, gateway;
 12.1096 -  Ipv6Address src6, dest6, gateway6;
 12.1097 -  uint32_t index = 0;
 12.1098 -  int attr_flags[RouteMessage::RT_A_MAX] = {0};
 12.1099 -  uint8_t dstlen = rtmsg.GetDstLength ();
 12.1100 -
 12.1101 -  //get necessary information for add/del, many attributes we not used
 12.1102 -  for (uint32_t i = 0; i < rtmsg.GetNNetlinkAttribute (); i ++)
 12.1103 -    {
 12.1104 -      NetlinkAttribute attr = rtmsg.GetNetlinkAttribute (i);
 12.1105 -      uint32_t attr_type = attr.GetAttrType ();
 12.1106 -      attr_flags[attr_type] = 1;
 12.1107 -
 12.1108 -      switch(attr_type)
 12.1109 -        {
 12.1110 -        case RouteMessage::RT_A_DST:
 12.1111 -          if (family == AF_INET)
 12.1112 -            {
 12.1113 -              dest = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 12.1114 -            }
 12.1115 -          else if (family == AF_INET6)
 12.1116 -            {
 12.1117 -              dest6 = Ipv6Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 12.1118 -            }
 12.1119 -          break;
 12.1120 -        case RouteMessage::RT_A_SRC:
 12.1121 -          if (family == AF_INET)
 12.1122 -            {
 12.1123 -              src = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 12.1124 -            }
 12.1125 -          else if (family == AF_INET6)
 12.1126 -            {
 12.1127 -              src6 = Ipv6Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 12.1128 -            }
 12.1129 -          break;
 12.1130 -        case RouteMessage::RT_A_OIF:
 12.1131 -          index = attr.GetAttrPayload ().GetU32 ();
 12.1132 -          break;
 12.1133 -        case RouteMessage::RT_A_GATEWAY:
 12.1134 -          if (family == AF_INET)
 12.1135 -            {
 12.1136 -              gateway = Ipv4Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 12.1137 -            }
 12.1138 -          else if (family == AF_INET6)
 12.1139 -            {
 12.1140 -              gateway6 = Ipv6Address::ConvertFrom (attr.GetAttrPayload ().GetAddress ());
 12.1141 -            }
 12.1142 -          break;
 12.1143 -        case RouteMessage::RT_A_IIF:
 12.1144 -        case RouteMessage::RT_A_PRIORITY:
 12.1145 -        case RouteMessage::RT_A_PREFSRC:
 12.1146 -        case RouteMessage::RT_A_METRICS:
 12.1147 -        case RouteMessage::RT_A_MULTIPATH:
 12.1148 -        case RouteMessage::RT_A_PROTOINFO:
 12.1149 -        case RouteMessage::RT_A_FLOW:
 12.1150 -        case RouteMessage::RT_A_CACHEINFO:
 12.1151 -        case RouteMessage::RT_A_SESSION:
 12.1152 -        case RouteMessage::RT_A_MP_ALGO:
 12.1153 -        case RouteMessage::RT_A_TABLE:
 12.1154 -          NS_LOG_INFO("route attribute not used by ns3" << attr_type);
 12.1155 -          //not used by ns3
 12.1156 -          break;
 12.1157 -        }
 12.1158 -    }
 12.1159 -
 12.1160 -  // Sigh....
 12.1161 -  Ptr<Ipv4>ipv4 = m_node->GetObject<Ipv4> ();
 12.1162 -  Ipv4StaticRoutingHelper routingHelper;
 12.1163 -  Ptr<Ipv4StaticRouting> ipv4Static = routingHelper.GetStaticRouting (ipv4);
 12.1164 -
 12.1165 -  Ptr<Ipv6>ipv6 = m_node->GetObject<Ipv6> ();
 12.1166 -  Ipv6StaticRoutingHelper routingHelper6;
 12.1167 -  Ptr<Ipv6StaticRouting> ipv6Static = routingHelper6.GetStaticRouting (ipv6);
 12.1168 -
 12.1169 -  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Route message, type: " << type << "; from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 12.1170 -      << " to " << dest<< " through " << gateway);
 12.1171 -
 12.1172 -  if (type == NETLINK_RTM_NEWROUTE)
 12.1173 -    {
 12.1174 -      //ns3 add a route entry only depends on 2 or 3 attribute
 12.1175 -      //other route msg attibute were ignored
 12.1176 -      if (attr_flags[RouteMessage::RT_A_DST])
 12.1177 -        {
 12.1178 -          if (family == AF_INET)
 12.1179 -            {
 12.1180 -              if (!attr_flags[RouteMessage::RT_A_OIF])
 12.1181 -                {
 12.1182 -                  bool found = 0;
 12.1183 -                  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
 12.1184 -                    {
 12.1185 -                      for (uint32_t j = 0; j < ipv4->GetNAddresses (i); j++)
 12.1186 -                        {
 12.1187 -                          if ((attr_flags[RouteMessage::RT_A_GATEWAY]))
 12.1188 -                            {
 12.1189 -                              Ipv4Mask mask = ipv4->GetAddress (i, j).GetMask ();
 12.1190 -                              if (mask.IsMatch (ipv4->GetAddress (i, j).GetLocal (), gateway))
 12.1191 -                                {
 12.1192 -                                  index = i;
 12.1193 -                                  found = true;
 12.1194 -                                  break;
 12.1195 -                                }
 12.1196 -                            }
 12.1197 -                          if (found) break;
 12.1198 -                        }
 12.1199 -                    }
 12.1200 -                  if (!found)
 12.1201 -                    {
 12.1202 -                      NS_LOG_DEBUG ("No suitable interface to add an route entry");
 12.1203 -                      m_errno = ERROR_ADDRNOTAVAIL;
 12.1204 -                      return -1;
 12.1205 -                    }
 12.1206 -                }
 12.1207 -            if (dstlen == 32)
 12.1208 -              {
 12.1209 -                int exist_flag = 0;
 12.1210 -                for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); ++i)
 12.1211 -                  {
 12.1212 -                    Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 12.1213 -                    if (dest == rt.GetDest ())
 12.1214 -                      {
 12.1215 -                        exist_flag = 1;
 12.1216 -                      }
 12.1217 -                  }
 12.1218 -
 12.1219 -                if (exist_flag)
 12.1220 -                  { //route to dest already exists
 12.1221 -                    int delete_flag = 0;
 12.1222 -                    if (nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_REPLACE)
 12.1223 -                      {
 12.1224 -                        for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); ++i)
 12.1225 -                          {
 12.1226 -                            Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 12.1227 -                            if (dest == rt.GetDest ())
 12.1228 -                              {
 12.1229 -                                ipv4Static->RemoveRoute (i);
 12.1230 -                                NS_LOG_DEBUG ("Route from  " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << " to "
 12.1231 -                                    << dest << " through " << gateway << " removed");
 12.1232 -                                delete_flag = 1;
 12.1233 -                              }
 12.1234 -                          }
 12.1235 -
 12.1236 -                        if (!delete_flag)
 12.1237 -                          {
 12.1238 -                             NS_LOG_INFO ("no route entry removed by dest address in new route sector " << dest);
 12.1239 -                             m_errno = ERROR_INVAL;
 12.1240 -                             return -1;
 12.1241 -                           }
 12.1242 -                      }
 12.1243 -                    else
 12.1244 -                      {
 12.1245 -                        NS_LOG_DEBUG ("Route exists but overwriting declined!");
 12.1246 -                      }
 12.1247 -                    if ((attr_flags[RouteMessage::RT_A_GATEWAY]))
 12.1248 -                      {
 12.1249 -                        NS_LOG_DEBUG (Simulator::Now().GetSeconds() << "Overwrite route from "
 12.1250 -                            << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << " to " << dest<< " through " << gateway << " with index" << index);
 12.1251 -                        ipv4Static->AddHostRouteTo (dest, gateway, index);
 12.1252 -                      }
 12.1253 -                    else
 12.1254 -                      {
 12.1255 -                        NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Overwrite route from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 12.1256 -                            << " to " << dest<< " through " << "self" << " with index" << index);
 12.1257 -                        ipv4Static->AddHostRouteTo (dest, index);
 12.1258 -                      }
 12.1259 -                }
 12.1260 -                else
 12.1261 -                  { //route to dest doesn't exist
 12.1262 -                    if (nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_CREATE)
 12.1263 -                      {
 12.1264 -                        if (attr_flags[RouteMessage::RT_A_GATEWAY])
 12.1265 -                          {
 12.1266 -                            NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Add new route from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 12.1267 -                                << " to " << dest<< " through " << gateway << " with index" << index);
 12.1268 -                            ipv4Static->AddHostRouteTo (dest, gateway, index);
 12.1269 -                          }
 12.1270 -                        else
 12.1271 -                          {
 12.1272 -                            NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Add new route from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 12.1273 -                                << " to " << dest<< " through " << "self" << " with index" << index);
 12.1274 -                            ipv4Static->AddHostRouteTo (dest, index);
 12.1275 -                          }
 12.1276 -                      }
 12.1277 -                    else
 12.1278 -                      {
 12.1279 -                        NS_LOG_ERROR ("Route doesn't exist but writing declined!");
 12.1280 -                      }
 12.1281 -                  }
 12.1282 -
 12.1283 -                NS_LOG_DEBUG ("=After change attempt=");
 12.1284 -                //Dump of table
 12.1285 -                NS_LOG_DEBUG (m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << ":");
 12.1286 -                for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); ++i)
 12.1287 -                  {
 12.1288 -                    Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 12.1289 -                    NS_LOG_DEBUG (rt.GetDest () << " through " << rt.GetGateway ());
 12.1290 -                  }
 12.1291 -                NS_LOG_DEBUG ("= = = = = = = = = = =");
 12.1292 -              }
 12.1293 -            else // dstlen != 32
 12.1294 -              {
 12.1295 -                if (attr_flags[RouteMessage::RT_A_GATEWAY])
 12.1296 -                  {
 12.1297 -                    ipv4Static->AddNetworkRouteTo (dest, Ipv4Mask (~(1<<(32 - dstlen))+1), gateway, index);
 12.1298 -                  }
 12.1299 -                else
 12.1300 -                  {
 12.1301 -                    ipv4Static->AddNetworkRouteTo (dest, Ipv4Mask (~(1<<(32 - dstlen))+1), index);
 12.1302 -                  }
 12.1303 -              }
 12.1304 -          }
 12.1305 -          else if (family == AF_INET6)
 12.1306 -            {
 12.1307 -            if (!attr_flags[RouteMessage::RT_A_OIF])
 12.1308 -              {
 12.1309 -#ifdef FIXME
 12.1310 -              if (ipv6->GetIfIndexForDestination (gateway6, index) == false)
 12.1311 -                {
 12.1312 -                  NS_LOG_INFO ("No suitable interface to add an route entry");
 12.1313 -                  m_errno = ERROR_ADDRNOTAVAIL;
 12.1314 -                  return -1;
 12.1315 -                }
 12.1316 -#endif
 12.1317 -              }
 12.1318 -
 12.1319 -            Ipv6Prefix pref (dstlen);
 12.1320 -            if (attr_flags[RouteMessage::RT_A_GATEWAY])
 12.1321 -              {
 12.1322 -                ipv6Static->AddNetworkRouteTo (dest6, pref, gateway6, index);
 12.1323 -              }
 12.1324 -            else
 12.1325 -              {
 12.1326 -                ipv6Static->AddNetworkRouteTo (dest6, pref, Ipv6Address("::"), index);
 12.1327 -              }
 12.1328 -            }
 12.1329 -          }
 12.1330 -        else
 12.1331 -          {
 12.1332 -            NS_LOG_INFO("too few attributes to add an route entry");
 12.1333 -            m_errno = ERROR_INVAL;
 12.1334 -            return -1;
 12.1335 -          }
 12.1336 -    }
 12.1337 -  else if (type == NETLINK_RTM_DELROUTE)
 12.1338 -    {
 12.1339 -      NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "Route delete request from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ()
 12.1340 -          << " to " << dest<< " through " << gateway);
 12.1341 -      if (attr_flags[RouteMessage::RT_A_DST])
 12.1342 -        {
 12.1343 -          int delete_flag = 0;
 12.1344 -
 12.1345 -          if (family == AF_INET)
 12.1346 -            {
 12.1347 -              for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); i ++)
 12.1348 -                {
 12.1349 -                Ipv4RoutingTableEntry rt = ipv4Static->GetRoute (i);
 12.1350 -                if (gateway == rt.GetGateway () && dest == rt.GetDest ())
 12.1351 -                  {
 12.1352 -                    ipv4Static->RemoveRoute (i);
 12.1353 -                    delete_flag = 1;
 12.1354 -                  }
 12.1355 -                }
 12.1356 -            }
 12.1357 -          else if (family == AF_INET6)
 12.1358 -            {
 12.1359 -              for (uint32_t i = 0; i < ipv6Static->GetNRoutes (); i ++)
 12.1360 -                {
 12.1361 -                Ipv6RoutingTableEntry rt = ipv6Static->GetRoute (i);
 12.1362 -                if (gateway6 == rt.GetGateway () && dest6 == rt.GetDest ())
 12.1363 -                  {
 12.1364 -                    ipv6Static->RemoveRoute (i);
 12.1365 -                    delete_flag = 1;
 12.1366 -                  }
 12.1367 -                }
 12.1368 -            }
 12.1369 -
 12.1370 -          if (!delete_flag)
 12.1371 -            {
 12.1372 -              NS_LOG_INFO ("no route entry removed by dest address " << dest);
 12.1373 -              m_errno = ERROR_INVAL;
 12.1374 -              return -1;
 12.1375 -            }
 12.1376 -        }
 12.1377 -      else
 12.1378 -        {
 12.1379 -          NS_LOG_INFO ("too few attributes to add an route entry");
 12.1380 -          m_errno = ERROR_INVAL;
 12.1381 -          return -1;    
 12.1382 -        }
 12.1383 -    }
 12.1384 -  else// type == NETLINK_RTM_GETROUTE
 12.1385 -    {
 12.1386 -      NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "GetRoute "<< "from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal () << " to " << dest);
 12.1387 -      if (!attr_flags[RouteMessage::RT_A_DST])
 12.1388 -        {
 12.1389 -          NS_LOG_INFO ("too few attributes to get an route entry");
 12.1390 -          m_errno = ERROR_INVAL;
 12.1391 -          return -1;
 12.1392 -        }
 12.1393 -      
 12.1394 -      int get_flag = 0;
 12.1395 -      if (family == AF_INET)
 12.1396 -        {
 12.1397 -          for (uint32_t i = 0; i < ipv4Static->GetNRoutes (); i ++)
 12.1398 -            {
 12.1399 -              Ipv4RoutingTableEntry route = ipv4Static->GetRoute (i);
 12.1400 -              //find the route entry with same dest address and send unicast to user space
 12.1401 -              if (dest.IsEqual (route.GetDest ()))
 12.1402 -                {
 12.1403 -                  //                Ptr<Ipv4>ipv4 = m_node->GetObject<Ipv4> ();
 12.1404 -                  NetlinkMessage nlmsg_route;
 12.1405 -                  NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, 0, 
 12.1406 -                                                                   nlmsg.GetHeader ().GetMsgSeq (), m_srcPid);
 12.1407 -                  RouteMessage rtmsg;
 12.1408 -
 12.1409 -                  //fill rtmsg and attributes
 12.1410 -                  rtmsg.SetFamily (AF_INET);
 12.1411 -                  rtmsg.SetDstLength (32);
 12.1412 -                  rtmsg.SetSrcLength (0);
 12.1413 -                  rtmsg.SetTos (0);//not clear
 12.1414 -                  rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
 12.1415 -                  rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
 12.1416 -                  rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
 12.1417 -                  rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
 12.1418 -
 12.1419 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
 12.1420 -                  //ns3 use local address as the route src address
 12.1421 -                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, ipv4->GetSourceAddress(route.GetDest ())));
 12.1422 -                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, ipv4->GetSourceAddress(route.GetDest ())));
 12.1423 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface ()));
 12.1424 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface ()));
 12.1425 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway ()));
 12.1426 -
 12.1427 -                  //fill an netlink message body
 12.1428 -                  nlmsg_route.SetHeader (nhr);
 12.1429 -                  nlmsg_route.SetRouteMessage (rtmsg);
 12.1430 -                  
 12.1431 -                  SendMessageUnicast (nlmsg_route, m_srcPid, 1);
 12.1432 -                  get_flag = 1;
 12.1433 -                }
 12.1434 -            }
 12.1435 -        }
 12.1436 -      else if (family == AF_INET6)
 12.1437 -        {
 12.1438 -          for (uint32_t i = 0; i < ipv6Static->GetNRoutes(); i ++)
 12.1439 -            {
 12.1440 -              Ipv6RoutingTableEntry route = ipv6Static->GetRoute (i);
 12.1441 -              //find the route entry with same dest address and send unicast to user space
 12.1442 -              if (dest6.IsEqual (route.GetDest ()))
 12.1443 -                {
 12.1444 -                  NetlinkMessage nlmsg_route;
 12.1445 -                  NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWROUTE, 0, 
 12.1446 -                                                                   nlmsg.GetHeader ().GetMsgSeq (), m_srcPid);
 12.1447 -                  RouteMessage rtmsg;
 12.1448 -
 12.1449 -                  //fill rtmsg and attributes
 12.1450 -                  rtmsg.SetFamily (AF_INET6);
 12.1451 -                  rtmsg.SetDstLength (32);
 12.1452 -                  rtmsg.SetSrcLength (0);
 12.1453 -                  rtmsg.SetTos (0);//not clear
 12.1454 -                  rtmsg.SetTableId (RouteMessage::RT_TABLE_MAIN);
 12.1455 -                  rtmsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
 12.1456 -                  rtmsg.SetProtocol (RouteMessage::RT_PROT_UNSPEC);
 12.1457 -                  rtmsg.SetFlags (RouteMessage::RT_F_CLONED);
 12.1458 -
 12.1459 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_DST, ADDRESS, route.GetDest ()));
 12.1460 -                  //ns3 use local address as the route src address
 12.1461 -                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_SRC, ADDRESS, ipv6->GetSourceAddress(route.GetDest ())));
 12.1462 -                  // rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_PREFSRC, ADDRESS, ipv6->GetSourceAddress(route.GetDest ())));
 12.1463 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_IIF, U32, route.GetInterface ()));
 12.1464 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_OIF, U32, route.GetInterface ()));
 12.1465 -                  rtmsg.AppendAttribute (NetlinkAttribute (RouteMessage::RT_A_GATEWAY, ADDRESS, route.GetGateway ()));
 12.1466 -
 12.1467 -                  //fill an netlink message body
 12.1468 -                  nlmsg_route.SetHeader (nhr);
 12.1469 -                  nlmsg_route.SetRouteMessage (rtmsg);
 12.1470 -
 12.1471 -                  SendMessageUnicast (nlmsg_route, m_srcPid, 1);
 12.1472 -                  get_flag = 1;
 12.1473 -                }
 12.1474 -            }
 12.1475 -        }
 12.1476 -      
 12.1477 -      if (!get_flag)
 12.1478 -        {
 12.1479 -          NS_LOG_INFO ("no route entry exist by dest address" << dest);
 12.1480 -          m_errno = ERROR_INVAL;
 12.1481 -          return -1;
 12.1482 -        }
 12.1483 -    }
 12.1484 -
 12.1485 -  //then send an broadcast message, let all user know this operation happened
 12.1486 -  MultipartNetlinkMessage nlmsg_multi;
 12.1487 -  NetlinkMessage nlmsg_broadcast = nlmsg;
 12.1488 -  NetlinkMessage nlmsg_done;
 12.1489 -  NetlinkMessageHeader nhr_done = NetlinkMessageHeader (NETLINK_MSG_DONE, NETLINK_MSG_F_MULTI, 0, 0);
 12.1490 -  nlmsg_done.SetHeader (nhr_done);
 12.1491 -  nlmsg_multi.AppendMessage (nlmsg);
 12.1492 -  nlmsg_multi.AppendMessage (nlmsg_done);
 12.1493 -  SendMessageBroadcast (nlmsg_multi, 0, NETLINK_RTM_GRP_IPV4_ROUTE, GetNode ());
 12.1494 -  //   SendMessageBroadcast(nlmsg_broadcast, 0, RTMGRP_IPV6_ROUTE);
 12.1495 -  return 0;
 12.1496 -}
 12.1497 -
 12.1498 -int32_t
 12.1499 -NetlinkSocket::NotifyIfLinkMessage (Address address, uint16_t type, uint8_t family)
 12.1500 -{
 12.1501 -  NS_ASSERT_MSG (false, "Not implemented yet (NotifyIfLinkMessage)");
 12.1502 -  return 0;
 12.1503 -}
 12.1504 -
 12.1505 -int32_t
 12.1506 -NetlinkSocket::NotifyIfAddrMessage (Ipv6Interface* interface, Ipv6Address addr, int cmd)
 12.1507 -{
 12.1508 -  MultipartNetlinkMessage nlmsg_multi;
 12.1509 -  NetlinkMessage nlmsg_ifa;
 12.1510 -  NetlinkMessageHeader nhr = NetlinkMessageHeader (cmd, NETLINK_MSG_F_MULTI, 0, 0);
 12.1511 -  InterfaceAddressMessage ifamsg;
 12.1512 -
 12.1513 -  NS_ASSERT_MSG (false, "Not implemented yet (NotifyIfAddrMessage)");
 12.1514 -
 12.1515 -  // FIXME!
 12.1516 -  Ipv6Prefix prefix = Ipv6Prefix(64);
 12.1517 -
 12.1518 -  //here get the address mask length
 12.1519 -  uint8_t bytes[16];
 12.1520 -  prefix.GetBytes (bytes);
 12.1521 -  uint8_t mask_len = 0;
 12.1522 -  for (int j = 0; j < 16; j++)
 12.1523 -    {
 12.1524 -      while (bytes[j])
 12.1525 -        {
 12.1526 -          bytes[j] = bytes[j] << 1;
 12.1527 -          mask_len ++;
 12.1528 -        }
 12.1529 -    }
 12.1530 -      
 12.1531 -  ifamsg.SetInterfaceIndex (interface->GetDevice ()->GetIfIndex ());
 12.1532 -  ifamsg.SetFamily (AF_INET6);
 12.1533 -  ifamsg.SetLength (mask_len);
 12.1534 -  ifamsg.SetFlags (0);
 12.1535 -  ifamsg.SetScope (RouteMessage::RT_SCOPE_UNIVERSE);
 12.1536 -
 12.1537 -  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LOCAL,    ADDRESS, addr));
 12.1538 -  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ADDRESS,  ADDRESS, addr));
 12.1539 -  //  ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_BROADCAST,ADDRESS, bcast));
 12.1540 -  //      ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_LABEL,    STRING,  "ns3-ifaddr"));//not used in ns3
 12.1541 -  //ifamsg.AppendAttribute (NetlinkAttribute (InterfaceAddressMessage::IF_A_ANYCAST,  ADDRESS, Ipv4Address("0.0.0.0")));//not used in ns3
 12.1542 -  //XXXother attributes not used by ns3
 12.1543 -
 12.1544 -  nlmsg_ifa.SetHeader (nhr);
 12.1545 -  nlmsg_ifa.SetInterfaceAddressMessage (ifamsg);
 12.1546 -
 12.1547 -  NetlinkMessage nlmsg_done;
 12.1548 -  NetlinkMessageHeader nhr_done = NetlinkMessageHeader (NETLINK_MSG_DONE, NETLINK_MSG_F_MULTI, 0, 0);
 12.1549 -  nlmsg_done.SetHeader (nhr_done);
 12.1550 -
 12.1551 -  nlmsg_multi.AppendMessage (nlmsg_ifa);
 12.1552 -  nlmsg_multi.AppendMessage (nlmsg_done);
 12.1553 -
 12.1554 -  SendMessageBroadcast (nlmsg_multi, 0, RTMGRP_IPV6_IFADDR, interface->GetDevice ()->GetNode ());  
 12.1555 -  return 0;
 12.1556 -}
 12.1557 -
 12.1558 -#ifdef FIXME
 12.1559 -int32_t
 12.1560 -NetlinkSocket::NotifyRouteMessage(Ojbect route, uint16_t type, uint8_t family)
 12.1561 -{
 12.1562 -  NetlinkMessage nlmsg_broadcast = nlmsg;
 12.1563 -  NetlinkMessageHeader nhr;
 12.1564 -  NS_ASSERT_MSG (false, "Not implemented yet");
 12.1565 -
 12.1566 -  nhr.SetMsgLen (nlmsg.GetHeader ().GetMsgLen ());
 12.1567 -  nhr.SetMsgType (nlmsg.GetHeader ().GetMsgType ());
 12.1568 -  nlmsg_broadcast.SetHeader (nhr);
 12.1569 -  SendMessageBroadcast (nlmsg_broadcast, 0, RTMGRP_IPV6_ROUTE);
 12.1570 -  return 0;
 12.1571 -}
 12.1572 -#endif
 12.1573 -
 12.1574 -}//namespace ns3
    13.1 --- a/model/netlink-socket.h	Tue Apr 19 23:13:50 2011 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,205 +0,0 @@
    13.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    13.5 -/*
    13.6 - * Copyright (c) 2008 Liu Jian
    13.7 - *
    13.8 - * This program is free software; you can redistribute it and/or modify
    13.9 - * it under the terms of the GNU General Public License version 2 as
   13.10 - * published by the Free Software Foundation;
   13.11 - *
   13.12 - * This program is distributed in the hope that it will be useful,
   13.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.15 - * GNU General Public License for more details.
   13.16 - *
   13.17 - * You should have received a copy of the GNU General Public License
   13.18 - * along with this program; if not, write to the Free Software
   13.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.20 - *
   13.21 - * Author: Liu Jian <liujatp@gmail.com>
   13.22 - *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   13.23 - */
   13.24 -#ifndef NETLINK_SOCKET_H
   13.25 -#define NETLINK_SOCKET_H
   13.26 -
   13.27 -#include <stdint.h>
   13.28 -#include <queue>
   13.29 -#include "netlink-message.h"
   13.30 -#include "ns3/callback.h"
   13.31 -#include "ns3/ptr.h"
   13.32 -#include "ns3/traced-callback.h"
   13.33 -#include "ns3/socket.h"
   13.34 -#include "ns3/ipv4-address.h"
   13.35 -#include "ns3/ipv6-address.h"
   13.36 -#include "ns3/ipv6-interface.h"
   13.37 -
   13.38 -namespace ns3 {
   13.39 -
   13.40 -class Node;
   13.41 -class Packet;
   13.42 -class NetlinkSocketAddress;
   13.43 -
   13.44 -/**
   13.45 -* \brief A NetlinkSocket is  used  to transfer information 
   13.46 -between kernel and userspace processes .
   13.47 -*
   13.48 -* here we focus on NETLINK_ROUTE: Receives routing and link
   13.49 -* updates and may be used to modify  the  routing  tables 
   13.50 -* (both IPv4 and IPv6), IP addresses, link parame- ters, neighbor
   13.51 -* setups, queueing disciplines, traffic classes and packet 
   13.52 -* classifiers (see rtnetlink (7)). This socket type is very similar
   13.53 -* to the linux and BSD "packet" sockets.
   13.54 -*
   13.55 -* Here is a summary of the semantics of this class:
   13.56 -* - Bind: Bind uses only the protocol and device fields of the 
   13.57 -*       NetlinkSocketAddress.
   13.58 -*
   13.59 -* - Send: send the input packet to the underlying kernel space
   13.60 -*       with its own address. The socket must  be bound.
   13.61 -*
   13.62 -* - Recv: receive packet from the kernel space.
   13.63 -*
   13.64 -* - Accept: not allowed
   13.65 -* - Connect: not allowed
   13.66 -*/
   13.67 -class NetlinkSocket : public Socket
   13.68 -{
   13.69 -public:
   13.70 -  static TypeId GetTypeId (void);
   13.71 -
   13.72 -  NetlinkSocket ();
   13.73 -  virtual ~NetlinkSocket ();
   13.74 -
   13.75 -  void SetNode (Ptr<Node> node);
   13.76 -
   13.77 -  virtual enum SocketErrno GetErrno (void) const;
   13.78 -  virtual enum Socket::SocketType GetSocketType (void) const;
   13.79 -  virtual Ptr<Node> GetNode (void) const;
   13.80 -  virtual int Bind (void);
   13.81 -  virtual int Bind (const Address & address);
   13.82 -  virtual int Close (void);
   13.83 -  virtual int ShutdownSend (void);
   13.84 -  virtual int ShutdownRecv (void);
   13.85 -  virtual int Connect (const Address &address);
   13.86 -  virtual int Listen (void);
   13.87 -  virtual uint32_t GetTxAvailable (void) const;
   13.88 -  virtual int Send (Ptr<Packet> p, uint32_t flags);
   13.89 -  virtual int SendTo(Ptr<Packet> p, uint32_t flags, const Address &toAddress);
   13.90 -  virtual uint32_t GetRxAvailable (void) const;
   13.91 -  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
   13.92 -  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, 
   13.93 -                                Address &fromAddress);
   13.94 -  virtual int GetSockName (Address &address) const; 
   13.95 -  virtual int GetPeerName (Address &address) const;
   13.96 -  virtual bool SetAllowBroadcast (bool allowBroadcast);
   13.97 -  virtual bool GetAllowBroadcast () const;
   13.98 -
   13.99 -  uint32_t GetSrcPid (void) const;
  13.100 -  uint32_t GetSrcGroups (void)const;
  13.101 -  uint32_t GetDstPid (void) const;
  13.102 -  uint32_t GetDstGroups (void)const;
  13.103 -  int32_t NotifyIfAddrMessage (Ipv6Interface* interface, Ipv6Address addr, int cmd);
  13.104 -  int32_t NotifyIfLinkMessage (Address address, uint16_t type, uint8_t family);
  13.105 -  //  int32_t NotifyRouteMessage(Ojbect route, uint16_t type, uint8_t family);
  13.106 -
  13.107 -private:
  13.108 -  int DoBind (const NetlinkSocketAddress &address);
  13.109 -  virtual void DoDispose (void);
  13.110 -  void ForwardUp (Ptr<Packet> p, NetlinkSocketAddress &address);
  13.111 -
  13.112 -
  13.113 -
  13.114 -  /**
  13.115 - * the functions below were for kernel parsing netlink message,set private here
  13.116 - * when netlink msg sent to kernel through netlink socket, it was parsed in kernel
  13.117 - * space, then, kernel add/del its route/interface/link table or dump all information
  13.118 - * to user space
  13.119 - */
  13.120 -
  13.121 -  int32_t HandleMessage (const NetlinkMessage &nlmsg);
  13.122 -  /**
  13.123 -  * when kernel find the message truncated or user need an ACK response,
  13.124 -  * it send ACK back to user space, with the error code(0 for ACK, > 0 for error).
  13.125 -  */
  13.126 -  void SendAckMessage (const NetlinkMessage &nlmsg, int32_t errorcode);
  13.127 -
  13.128 -  /**
  13.129 -  * \brief unicast an message to user
  13.130 -  * \param nlmsg the netlink message to transmit
  13.131 -  * \param pid the netlink pid of destination socket
  13.132 -  * \param nonbloack always true
  13.133 -  */
  13.134 -  int32_t SendMessageUnicast (const MultipartNetlinkMessage &nlmsg, 
  13.135 -                              uint32_t pid, int32_t nonblock);
  13.136 -  /**
  13.137 -  * \brief spread message to netlink group user
  13.138 -  * \param nlmsg the netlink message to transmit
  13.139 -  * \param pid the netlink pid of the kernel, always 0
  13.140 -  * \param group multicast group id
  13.141 -  */
  13.142 -  static int32_t SendMessageBroadcast (const MultipartNetlinkMessage &nlmsg, 
  13.143 -                                       uint32_t pid, uint32_t group, Ptr<Node> node);
  13.144 -
  13.145 -  /**
  13.146 -  * these functions below are for NETLINK_ROUTE protocol, it handle the netlink 
  13.147 -  * message like linux kernel work.  this implementation follows the kernel code 
  13.148 -  * linux/rtnetlink.c, focus on "interface address, interface info and route entry",
  13.149 -  * now we will only simply support three types operations of  NETLINK_ROUTE 
  13.150 -  * protocol
  13.151 -  */
  13.152 -  
  13.153 -  /**
  13.154 -  * \returns 0 if messge not processed, < 0 for success or an error.
  13.155 -  * this function would call dumping/doing functions to  
  13.156 -  */
  13.157 -  int32_t HandleNetlinkRouteMessage (const NetlinkMessage &nlmsg);
  13.158 -  
  13.159 -  /**
  13.160 -  * \returns 0 if dumping operation is OK, < 0 for an error.
  13.161 -  */ 
  13.162 -  int32_t DumpNetlinkRouteMessage (const NetlinkMessage &nlmsg, 
  13.163 -                                   uint16_t type, uint8_t family);
  13.164 -  MultipartNetlinkMessage BuildInterfaceAddressDumpMessage (uint32_t pid,
  13.165 -                                                            uint32_t seq, uint8_t family);
  13.166 -  MultipartNetlinkMessage BuildInterfaceInfoDumpMessage (uint32_t pid,
  13.167 -                                                         uint32_t seq, uint8_t family);
  13.168 -  MultipartNetlinkMessage BuildRouteDumpMessage (uint32_t pid,
  13.169 -                                                 uint32_t seq, uint8_t family);
  13.170 -
  13.171 -  /**
  13.172 -  * \returns 0 if doing operation(ADD/DEL/GET) is OK, < 0 for an error.
  13.173 -  */
  13.174 -  int32_t DoNetlinkRouteMessage (const NetlinkMessage &nlmsg,
  13.175 -                                 uint16_t type, uint8_t family);
  13.176 -  int32_t DoInterfaceAddressMessage (const NetlinkMessage &nlmsg, 
  13.177 -                                     uint16_t type, uint8_t family);
  13.178 -  int32_t DoInterfaceInfoMessage (const NetlinkMessage &nlmsg, 
  13.179 -                                  uint16_t type, uint8_t family);
  13.180 -  int32_t DoRouteMessage (const NetlinkMessage &nlmsg, 
  13.181 -                          uint16_t type, uint8_t family);
  13.182 -
  13.183 -  int ErrnoToSimuErrno (void);
  13.184 -  Address ConvertFrom (uint8_t family, const Address &address);
  13.185 -
  13.186 -  Ptr<Node> m_node;
  13.187 -  enum SocketErrno m_errno;
  13.188 -  bool m_shutdownSend;
  13.189 -  bool m_shutdownRecv;
  13.190 -
  13.191 -  std::queue<Ptr<Packet> > m_dataReceiveQueue;
  13.192 -  uint32_t m_rxAvailable;
  13.193 -  TracedCallback<Ptr<const Packet> > m_dropTrace;
  13.194 -  // Socket options (attributes)
  13.195 -  uint32_t m_rcvBufSize;
  13.196 -
  13.197 -  uint32_t m_srcPid;
  13.198 -  uint32_t m_srcGroups;
  13.199 -  uint32_t m_dstPid;
  13.200 -  uint32_t m_dstGroups;
  13.201 -  Callback<void, Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
  13.202 -};
  13.203 -
  13.204 -}//namespace ns3
  13.205 -
  13.206 -#endif /* NETLINK_SOCKET_H */
  13.207 -
  13.208 -
    14.1 --- a/model/ns3-socket-fd-factory.cc	Tue Apr 19 23:13:50 2011 +0200
    14.2 +++ b/model/ns3-socket-fd-factory.cc	Thu May 05 09:28:21 2011 +0200
    14.3 @@ -3,7 +3,7 @@
    14.4  #include "unix-socket-fd.h"
    14.5  #include "unix-datagram-socket-fd.h"
    14.6  #include "unix-stream-socket-fd.h"
    14.7 -#include "netlink-socket-factory.h"
    14.8 +#include "ns3/netlink-socket-factory.h"
    14.9  #include "ns3/socket-factory.h"
   14.10  #include "ns3/socket.h"
   14.11  #include "ns3/uinteger.h"
   14.12 @@ -29,36 +29,52 @@
   14.13  UnixFd *
   14.14  Ns3SocketFdFactory::CreateSocket (int domain, int type, int protocol)
   14.15  {
   14.16 -  NS_ASSERT (domain == PF_INET || domain == PF_NETLINK || domain == PF_INET6);
   14.17 -
   14.18    UnixSocketFd *socket = 0;
   14.19    Ptr<Socket> sock;
   14.20  
   14.21 -  switch (type) {
   14.22 -  case SOCK_DGRAM: {
   14.23 -    TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
   14.24 -    Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   14.25 -    sock = factory->CreateSocket ();
   14.26 -    socket = new UnixDatagramSocketFd (sock);
   14.27 -  } break;
   14.28 -  case SOCK_RAW: {
   14.29 -    TypeId tid = TypeId::LookupByName ("ns3::Ipv4RawSocketFactory");
   14.30 -    Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   14.31 -    sock = factory->CreateSocket ();
   14.32 -    sock->SetAttribute ("Protocol", UintegerValue (protocol));
   14.33 -    socket = new UnixDatagramSocketFd (sock);
   14.34 -  } break;
   14.35 -  case SOCK_STREAM: {
   14.36 -    TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
   14.37 -    Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   14.38 -    sock = factory->CreateSocket ();
   14.39 -    socket = new UnixStreamSocketFd (sock);
   14.40 -  } break;
   14.41 -    default:
   14.42 -      // XXX insert netlink creation here.
   14.43 -      NS_FATAL_ERROR ("missing socket type");
   14.44 -      break;
   14.45 -  }
   14.46 +  if (domain == PF_INET)
   14.47 +    {
   14.48 +      switch (type) {
   14.49 +      case SOCK_DGRAM: {
   14.50 +	TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
   14.51 +	Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   14.52 +	sock = factory->CreateSocket ();
   14.53 +	socket = new UnixDatagramSocketFd (sock);
   14.54 +      } break;
   14.55 +      case SOCK_RAW: {
   14.56 +	TypeId tid = TypeId::LookupByName ("ns3::Ipv4RawSocketFactory");
   14.57 +	Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   14.58 +	sock = factory->CreateSocket ();
   14.59 +	sock->SetAttribute ("Protocol", UintegerValue (protocol));
   14.60 +	socket = new UnixDatagramSocketFd (sock);
   14.61 +      } break;
   14.62 +      case SOCK_STREAM: {
   14.63 +	TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
   14.64 +	Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   14.65 +	sock = factory->CreateSocket ();
   14.66 +	socket = new UnixStreamSocketFd (sock);
   14.67 +      } break;
   14.68 +      default:
   14.69 +	NS_FATAL_ERROR ("missing socket type");
   14.70 +	break;
   14.71 +      }
   14.72 +    }
   14.73 +  else if (domain == PF_NETLINK)
   14.74 +    {
   14.75 +      switch (type) {
   14.76 +      case SOCK_DGRAM: {
   14.77 +	sock = m_netlink->CreateSocket ();
   14.78 +	socket = new UnixDatagramSocketFd (sock);
   14.79 +      } break;
   14.80 +      default:
   14.81 +	NS_FATAL_ERROR ("missing socket type");
   14.82 +	break;
   14.83 +      }
   14.84 +    }
   14.85 +  else
   14.86 +    {
   14.87 +      NS_FATAL_ERROR ("unsupported domain");
   14.88 +    }
   14.89  
   14.90    return socket;
   14.91  }
    15.1 --- a/model/ns3-socket-fd-factory.h	Tue Apr 19 23:13:50 2011 +0200
    15.2 +++ b/model/ns3-socket-fd-factory.h	Thu May 05 09:28:21 2011 +0200
    15.3 @@ -5,7 +5,7 @@
    15.4  
    15.5  namespace ns3 {
    15.6  
    15.7 -class NetlinkSocketFactory;
    15.8 +class SocketFactory;
    15.9  
   15.10  class Ns3SocketFdFactory : public SocketFdFactory
   15.11  {
   15.12 @@ -14,7 +14,7 @@
   15.13    Ns3SocketFdFactory ();
   15.14    virtual UnixFd *CreateSocket (int domain, int type, int protocol);
   15.15   private:
   15.16 -  Ptr<NetlinkSocketFactory> m_netlink;
   15.17 +  Ptr<SocketFactory> m_netlink;
   15.18  };
   15.19  
   15.20  } // namespace ns3
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/netlink/netlink-attribute.cc	Thu May 05 09:28:21 2011 +0200
    16.3 @@ -0,0 +1,433 @@
    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-attribute.h"
   16.26 +#include "netlink-message.h"
   16.27 +#include "netlink-message-route.h"
   16.28 +#include "ns3/address-utils.h"
   16.29 +
   16.30 +namespace ns3 {
   16.31 +
   16.32 +
   16.33 +/***********************************************************************************
   16.34 +* \ NetlinkAttributeValue
   16.35 +***********************************************************************************/
   16.36 +NetlinkAttributeValue::NetlinkAttributeValue ()
   16.37 +{
   16.38 +  m_type = UNSPEC;
   16.39 +  m_u32 = 0;
   16.40 +}
   16.41 +
   16.42 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v)
   16.43 +{
   16.44 +  NS_ASSERT (type == U8);
   16.45 +  m_type = U8;
   16.46 +  m_u8 = v;
   16.47 +}
   16.48 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v)
   16.49 +{
   16.50 +  NS_ASSERT (type == U16);
   16.51 +  m_type = U16;
   16.52 +  m_u16 = v;
   16.53 +}
   16.54 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v)
   16.55 +{
   16.56 +  NS_ASSERT (type == U32);
   16.57 +  m_type = U32;
   16.58 +  m_u32 = v;
   16.59 +}
   16.60 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v)
   16.61 +{
   16.62 +  NS_ASSERT (type == U64);
   16.63 +  m_type = U64;
   16.64 +  m_u64 = v;
   16.65 +}
   16.66 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v)
   16.67 +{
   16.68 +  NS_ASSERT (type == STRING);
   16.69 +  m_type = STRING;
   16.70 +  m_string = v;
   16.71 +}
   16.72 +NetlinkAttributeValue:: NetlinkAttributeValue (NetlinkAttributeValueType type, Address v)
   16.73 +{
   16.74 +  NS_ASSERT (type == ADDRESS);
   16.75 +  m_type = ADDRESS;
   16.76 +  m_address = v;
   16.77 +}
   16.78 +
   16.79 +void
   16.80 +NetlinkAttributeValue::SetType (NetlinkAttributeValueType type)
   16.81 +{
   16.82 +  m_type = type;
   16.83 +}
   16.84 +NetlinkAttributeValueType
   16.85 +NetlinkAttributeValue::GetType (void) const
   16.86 +{
   16.87 +  return m_type;
   16.88 +}
   16.89 +void
   16.90 +NetlinkAttributeValue::SetAddress (Address value)
   16.91 +{
   16.92 +  m_address = value;
   16.93 +}
   16.94 +void
   16.95 +NetlinkAttributeValue::SetString (std::string value)
   16.96 +{
   16.97 +  m_string = value;
   16.98 +}
   16.99 +void
  16.100 +NetlinkAttributeValue::SetU64 (uint64_t value)
  16.101 +{
  16.102 +  m_u64 = value;
  16.103 +}
  16.104 +void
  16.105 +NetlinkAttributeValue::SetU32 (uint32_t value)
  16.106 +{
  16.107 +  m_u32 = value;
  16.108 +}
  16.109 +void
  16.110 +NetlinkAttributeValue::SetU16 (uint16_t value)
  16.111 +{
  16.112 +  m_u16 = value;
  16.113 +}
  16.114 +void
  16.115 +NetlinkAttributeValue::SetU8 (uint8_t value)
  16.116 +{
  16.117 +  m_u8 = value;
  16.118 +}
  16.119 +Address
  16.120 +NetlinkAttributeValue::GetAddress (void) const
  16.121 +{
  16.122 +  return m_address;
  16.123 +}
  16.124 +std::string
  16.125 +NetlinkAttributeValue::GetString (void) const
  16.126 +{
  16.127 +  return m_string;
  16.128 +}
  16.129 +uint64_t
  16.130 +NetlinkAttributeValue::GetU64 (void) const
  16.131 +{
  16.132 +  return m_u64;
  16.133 +}
  16.134 +uint32_t
  16.135 +NetlinkAttributeValue::GetU32 (void) const
  16.136 +{
  16.137 +  return m_u32;
  16.138 +}
  16.139 +uint16_t
  16.140 +NetlinkAttributeValue::GetU16 (void) const
  16.141 +{
  16.142 +  return m_u16;
  16.143 +}
  16.144 +uint8_t
  16.145 +NetlinkAttributeValue::GetU8 (void) const
  16.146 +{
  16.147 +  return m_u8;
  16.148 +}
  16.149 +
  16.150 +void
  16.151 +NetlinkAttributeValue::Serialize (Buffer::Iterator& start) const
  16.152 +{
  16.153 +  uint32_t len;
  16.154 +
  16.155 +  if (m_type == U8)
  16.156 +    {
  16.157 +      start.WriteU8 (m_u8);
  16.158 +      len = 1;
  16.159 +    }
  16.160 +  else if(m_type == U16)
  16.161 +    {
  16.162 +      start.WriteU16 (m_u16);
  16.163 +      len = 2;
  16.164 +    }
  16.165 +  else if(m_type == U32)
  16.166 +    {
  16.167 +      start.WriteU32 (m_u32);
  16.168 +      len = 4;
  16.169 +    }
  16.170 +  else if(m_type == STRING)
  16.171 +    {
  16.172 +      start.Write ((const uint8_t *)m_string.c_str (), (uint32_t)m_string.size ()+1);
  16.173 +      len = (uint32_t)m_string.size () + 1;
  16.174 +    }
  16.175 +  else if(m_type == ADDRESS)
  16.176 +    {
  16.177 +      WriteTo (start, m_address);
  16.178 +      len = m_address.GetLength ();
  16.179 +    }
  16.180 +  else
  16.181 +    {
  16.182 +      len = 0;
  16.183 +    }
  16.184 +  //netlink align
  16.185 +  start.WriteU8 (0, NETLINK_MSG_ALIGN (len) - len);
  16.186 +}
  16.187 +
  16.188 +uint32_t
  16.189 +NetlinkAttributeValue::DeserializeWithType (Buffer::Iterator& start, 
  16.190 +                                            NetlinkAttributeValueType_e type, uint16_t remaining)
  16.191 +{
  16.192 +  uint32_t len =0;
  16.193 +  m_type = type;  
  16.194 +
  16.195 +  if (m_type == U8)
  16.196 +    {
  16.197 +      m_u8 = start.ReadU8 ();
  16.198 +      len = 1;
  16.199 +    }
  16.200 +  else if (m_type == U16)
  16.201 +    {
  16.202 +      m_u16 = start.ReadU16 ();
  16.203 +      len = 2;
  16.204 +    }
  16.205 +  else if (m_type == U32)
  16.206 +    {
  16.207 +      m_u32 = start.ReadU32 ();
  16.208 +      len = 4;
  16.209 +    }
  16.210 +  else if (m_type == U64)
  16.211 +    {
  16.212 +      m_u64 = start.ReadU64 ();
  16.213 +    }  
  16.214 +  else if (m_type == STRING)
  16.215 +    {
  16.216 +      char buf[512];
  16.217 +      uint32_t i = 0;
  16.218 +      do 
  16.219 +      {
  16.220 +        buf[i] = start.ReadU8 ();
  16.221 +      } while (buf[i++]);
  16.222 +      
  16.223 +      m_string = std::string (buf);
  16.224 +      len = (uint32_t)m_string.size () + 1;
  16.225 +    }
  16.226 +  else if (m_type == ADDRESS)
  16.227 +    {
  16.228 +      ReadFrom (start, m_address, remaining);
  16.229 +      len = m_address.GetLength ();
  16.230 +    }
  16.231 +  else
  16.232 +    {
  16.233 +      len = 0;
  16.234 +    }
  16.235 +
  16.236 +  //netlink align
  16.237 +  uint8_t buf[4];
  16.238 +  start.Read (buf, NETLINK_MSG_ALIGN (len) - len);
  16.239 +  
  16.240 +  return NETLINK_MSG_ALIGN (len);
  16.241 +}
  16.242 +
  16.243 +uint32_t
  16.244 +NetlinkAttributeValue::GetSerializedSize ()const
  16.245 +{
  16.246 +  return NETLINK_MSG_ALIGN (GetSize ());
  16.247 +}
  16.248 +
  16.249 +uint32_t
  16.250 +NetlinkAttributeValue::GetSize () const
  16.251 +{
  16.252 +  uint32_t len;
  16.253 +
  16.254 +  if (m_type == U8)
  16.255 +    {
  16.256 +      len = 1;
  16.257 +    }
  16.258 +  else if(m_type == U16)
  16.259 +    {
  16.260 +      len =  2;
  16.261 +    }
  16.262 +  else if(m_type == U32)
  16.263 +    {
  16.264 +      len =  4;
  16.265 +    }
  16.266 +  else if (m_type == STRING)
  16.267 +    {
  16.268 +      len =  uint32_t (m_string.size () + 1);
  16.269 +    }
  16.270 +  else if (m_type == ADDRESS)
  16.271 +    {
  16.272 +      len =  m_address.GetLength ();
  16.273 +    }
  16.274 +  else
  16.275 +    {
  16.276 +      len = 0;
  16.277 +    }
  16.278 +
  16.279 +    return len;
  16.280 +}
  16.281 +
  16.282 +void
  16.283 +NetlinkAttributeValue::Print (std::ostream &os) const
  16.284 +{
  16.285 +  os << "NetlinkAttributeValue (type= " << m_type <<", v= ";
  16.286 +  if (m_type == U8)
  16.287 +    {
  16.288 +      os << m_u8;
  16.289 +    }
  16.290 +  else if (m_type == U16)
  16.291 +    {
  16.292 +      os << m_u16;
  16.293 +    }
  16.294 +  else if (m_type == U32)
  16.295 +    {
  16.296 +      os << m_u32;
  16.297 +    }
  16.298 +  else if (m_type == U64)
  16.299 +    {
  16.300 +      os << m_u64;
  16.301 +    }  
  16.302 +  else if (m_type == STRING)
  16.303 +    {
  16.304 +      os << m_string;
  16.305 +    }
  16.306 +  else if (m_type == ADDRESS)
  16.307 +    {
  16.308 +      os << "address(" << m_address <<")";
  16.309 +    }
  16.310 +  else
  16.311 +    {
  16.312 +      os << "NULL";
  16.313 +    }
  16.314 +  os <<")";
  16.315 +}
  16.316 +
  16.317 +
  16.318 +/***********************************************************************************
  16.319 +* \ NetlinkAttribute
  16.320 +***********************************************************************************/
  16.321 +
  16.322 +NetlinkAttribute::NetlinkAttribute ()
  16.323 +  : m_len(4),
  16.324 +    m_type (0)
  16.325 +{
  16.326 +}
  16.327 +
  16.328 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload)
  16.329 +{
  16.330 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  16.331 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  16.332 +  m_type = type;
  16.333 +}
  16.334 +
  16.335 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload)
  16.336 +{
  16.337 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  16.338 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  16.339 +  m_type = type;
  16.340 +}
  16.341 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload)
  16.342 +{
  16.343 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  16.344 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  16.345 +  m_type = type;;
  16.346 +}
  16.347 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload)
  16.348 +{
  16.349 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  16.350 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  16.351 +  m_type = type;
  16.352 +}
  16.353 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload)
  16.354 +{
  16.355 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  16.356 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  16.357 +  m_type = type;
  16.358 +}
  16.359 +NetlinkAttribute::NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload)
  16.360 +{
  16.361 +  m_payload = NetlinkAttributeValue (payloadtype, payload);
  16.362 +  m_len = NETLINK_MSG_ATTR_SIZE + m_payload.GetSize ();
  16.363 +  m_type = type;
  16.364 +}
  16.365 +
  16.366 +void
  16.367 +NetlinkAttribute::SetAttrLen (uint16_t v)
  16.368 +{
  16.369 +  m_len = v;
  16.370 +}
  16.371 +void 
  16.372 +NetlinkAttribute::SetAttrType (uint16_t v)
  16.373 +{
  16.374 +  m_type = v;
  16.375 +}
  16.376 +void
  16.377 +NetlinkAttribute::SetAttrPayload (NetlinkAttributeValue v)
  16.378 +{
  16.379 +  m_payload = v;
  16.380 +}
  16.381 +uint16_t
  16.382 +NetlinkAttribute::GetAttrLen () const
  16.383 +{
  16.384 +  return m_len;
  16.385 +}
  16.386 +uint16_t
  16.387 +NetlinkAttribute::GetAttrType () const
  16.388 +{
  16.389 +  return m_type;
  16.390 +}
  16.391 +NetlinkAttributeValue
  16.392 +NetlinkAttribute::GetAttrPayload() const
  16.393 +{
  16.394 +  return m_payload;
  16.395 +}
  16.396 +
  16.397 +void 
  16.398 +NetlinkAttribute::Print (std::ostream &os) const
  16.399 +{  
  16.400 +  os << "NetlinkAttribute "
  16.401 +     << "len: " << m_len << " "
  16.402 +     << "type: " << m_type<<" "
  16.403 +     << "payload:[";
  16.404 +  m_payload.Print(os);
  16.405 +  os<<"]";
  16.406 +}
  16.407 +
  16.408 +uint32_t 
  16.409 +NetlinkAttribute::GetSerializedSize (void) const
  16.410 +{
  16.411 +  /* this is the size of an nlattr payload. */
  16.412 +  return NETLINK_MSG_ATTR_SIZE + m_payload.GetSerializedSize ();
  16.413 +}
  16.414 +
  16.415 +void
  16.416 +NetlinkAttribute::Serialize (Buffer::Iterator& start) const
  16.417 +{
  16.418 +  start.WriteU16 (m_len);
  16.419 +  start.WriteU16 (m_type);
  16.420 +  m_payload.Serialize (start);
  16.421 +}
  16.422 +
  16.423 +uint32_t
  16.424 +NetlinkAttribute::Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[])
  16.425 +{
  16.426 +  NetlinkAttributeValueType type;
  16.427 +
  16.428 +  m_len = start.ReadU16 ();
  16.429 +  m_type = start.ReadU16 ();
  16.430 +  type = vtypes[m_type];
  16.431 +  m_payload.DeserializeWithType (start, type, m_len - 4);
  16.432 +
  16.433 +  return GetSerializedSize ();
  16.434 +}
  16.435 +
  16.436 +}; // namespace ns3
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/netlink/netlink-attribute.h	Thu May 05 09:28:21 2011 +0200
    17.3 @@ -0,0 +1,124 @@
    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_ATTRIBUTE_H
   17.26 +#define NETLINK_ATTRIBUTE_H
   17.27 +
   17.28 +
   17.29 +#include <stdint.h>
   17.30 +#include <string>
   17.31 +#include <ostream>
   17.32 +#include "ns3/address.h"
   17.33 +#include "ns3/buffer.h"
   17.34 +
   17.35 +namespace ns3 {
   17.36 +
   17.37 +/**
   17.38 +* \brief The Netlink Attribute
   17.39 +*/
   17.40 +
   17.41 +typedef enum NetlinkAttributeValueType_e {
   17.42 +  UNSPEC, // invalid initial value.
   17.43 +  U8,
   17.44 +  U16,
   17.45 +  U32,
   17.46 +  U64,
   17.47 +  STRING,
   17.48 +  ADDRESS,
   17.49 +}NetlinkAttributeValueType;
   17.50 +
   17.51 +class NetlinkAttributeValue
   17.52 +{
   17.53 +public:
   17.54 +  NetlinkAttributeValue ();
   17.55 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v);
   17.56 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v);
   17.57 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v);
   17.58 +  NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v);
   17.59 +  NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v);
   17.60 +  NetlinkAttributeValue (NetlinkAttributeValueType type, Address v);
   17.61 +  
   17.62 +  void Serialize (Buffer::Iterator& start) const;
   17.63 +  uint32_t DeserializeWithType (Buffer::Iterator& start, NetlinkAttributeValueType type, uint16_t remaining);
   17.64 +  uint32_t GetSerializedSize (void) const;
   17.65 +  uint32_t GetSize (void) const;
   17.66 +  void Print (std::ostream &os) const;
   17.67 +
   17.68 +  void SetType (NetlinkAttributeValueType type);
   17.69 +  NetlinkAttributeValueType GetType (void) const;
   17.70 +  void SetAddress (Address value);
   17.71 +  void SetString (std::string value);
   17.72 +  void SetU64 (uint64_t value);
   17.73 +  void SetU32 (uint32_t value);
   17.74 +  void SetU16 (uint16_t value);
   17.75 +  void SetU8 (uint8_t value);
   17.76 +  Address GetAddress (void) const;
   17.77 +  std::string GetString (void) const;
   17.78 +  uint64_t GetU64 (void) const;
   17.79 +  uint32_t GetU32 (void) const;
   17.80 +  uint16_t GetU16 (void) const;
   17.81 +  uint8_t GetU8 (void) const;
   17.82 +
   17.83 +private:
   17.84 +  NetlinkAttributeValueType m_type;
   17.85 +  uint64_t m_u64;
   17.86 +  uint32_t m_u32;
   17.87 +  uint16_t m_u16;
   17.88 +  uint8_t m_u8;
   17.89 +  std::string m_string;
   17.90 +  Address m_address;
   17.91 +};
   17.92 +
   17.93 +struct NetlinkAttribute
   17.94 +{
   17.95 +public:
   17.96 +  NetlinkAttribute ();
   17.97 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload);
   17.98 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload);
   17.99 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload);
  17.100 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload);
  17.101 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload);
  17.102 +  NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload);
  17.103 +
  17.104 +  //static TypeId GetTypeId (void);
  17.105 +  //virtual TypeId GetInstanceTypeId (void) const;
  17.106 +  void Print (std::ostream &os) const;
  17.107 +  uint32_t GetSerializedSize (void) const;
  17.108 +  void Serialize (Buffer::Iterator& start) const;
  17.109 +  uint32_t Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[]);
  17.110 +
  17.111 +  void SetAttrLen (uint16_t v);
  17.112 +  void SetAttrType (uint16_t v);
  17.113 +  void SetAttrPayload (NetlinkAttributeValue v);
  17.114 +  uint16_t GetAttrLen () const;
  17.115 +  uint16_t GetAttrType () const;
  17.116 +  NetlinkAttributeValue GetAttrPayload () const;
  17.117 +
  17.118 +private:
  17.119 +  static const int NETLINK_MSG_ATTR_SIZE = 4; /* size of the nlattr field*/
  17.120 +  uint16_t m_len;
  17.121 +  uint16_t m_type; 
  17.122 +  NetlinkAttributeValue m_payload;
  17.123 +};
  17.124 +
  17.125 +}; // namespace ns3
  17.126 +
  17.127 +#endif /* NETLINK_ATTRIBUTE_H */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/netlink/netlink-message-route.cc	Thu May 05 09:28:21 2011 +0200
    18.3 @@ -0,0 +1,647 @@
    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-route.h"
   18.26 +#include "netlink-message.h"
   18.27 +
   18.28 +namespace ns3 {
   18.29 +
   18.30 +/***********************************************************************************
   18.31 +* \ NetlinkPayload
   18.32 +***********************************************************************************/
   18.33 +TypeId 
   18.34 +NetlinkPayload::GetTypeId (void)
   18.35 +{
   18.36 +  static TypeId tid = TypeId ("ns3::NetlinkPayload")
   18.37 +    .SetParent<ObjectBase> ()
   18.38 +    ;
   18.39 +  return tid;
   18.40 +}
   18.41 +
   18.42 +
   18.43 +/***********************************************************************************
   18.44 +* \ GeneralMessage
   18.45 +***********************************************************************************/
   18.46 +
   18.47 +NS_OBJECT_ENSURE_REGISTERED (GeneralMessage);
   18.48 +NS_OBJECT_ENSURE_REGISTERED (InterfaceInfoMessage);
   18.49 +NS_OBJECT_ENSURE_REGISTERED (InterfaceAddressMessage);
   18.50 +NS_OBJECT_ENSURE_REGISTERED (RouteMessage);
   18.51 +
   18.52 +GeneralMessage::GeneralMessage ()
   18.53 +  : m_family(0)
   18.54 +{}
   18.55 +GeneralMessage::~GeneralMessage ()
   18.56 +{}
   18.57 +
   18.58 +void
   18.59 +GeneralMessage::SetFamily (uint8_t v)
   18.60 +{
   18.61 +  m_family = v;
   18.62 +}
   18.63 +uint8_t
   18.64 +GeneralMessage::GetFamily (void) const
   18.65 +{
   18.66 +  return m_family;
   18.67 +}
   18.68 +
   18.69 +TypeId 
   18.70 +GeneralMessage::GetTypeId (void)
   18.71 +{
   18.72 +  static TypeId tid = TypeId ("ns3::GeneralMessage")
   18.73 +    .SetParent<NetlinkPayload> ()
   18.74 +    .AddConstructor<GeneralMessage> ()
   18.75 +    ;
   18.76 +  return tid;
   18.77 +}
   18.78 +
   18.79 +TypeId 
   18.80 +GeneralMessage::GetInstanceTypeId (void) const
   18.81 +{
   18.82 +  return GetTypeId ();
   18.83 +}
   18.84 +void 
   18.85 +GeneralMessage::Print (std::ostream &os) const
   18.86 +{
   18.87 +  os << " ----GeneralMessage ("
   18.88 +     << "family: " << (uint32_t)m_family << ")"; 
   18.89 +}
   18.90 +
   18.91 +uint32_t 
   18.92 +GeneralMessage::GetSerializedSize (void) const
   18.93 +{
   18.94 +  /* this is the size of an nlmsghdr payload. */
   18.95 +  return NETLINK_MSG_ALIGN (NETLINK_GENMSG_SIZE);
   18.96 +}
   18.97 +
   18.98 +
   18.99 +void
  18.100 +GeneralMessage::Serialize (Buffer::Iterator& start) const
  18.101 +{
  18.102 +  start.WriteU8 (m_family);
  18.103 +  start.WriteU8 (0, 3);
  18.104 +}
  18.105 +
  18.106 +uint32_t
  18.107 +GeneralMessage::Deserialize (Buffer::Iterator& start)
  18.108 +{
  18.109 +  uint8_t buf[3];
  18.110 +  m_family = start.ReadU8 ();
  18.111 +  start.Read (buf, 3);
  18.112 +  return GetSerializedSize ();
  18.113 +}
  18.114 +uint32_t
  18.115 +GeneralMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  18.116 +{
  18.117 +  uint8_t buf[3];
  18.118 +  m_family = start.ReadU8 ();
  18.119 +  start.Read (buf, 3);
  18.120 +  return GetSerializedSize ();
  18.121 +}
  18.122 +
  18.123 +
  18.124 +uint32_t
  18.125 +GeneralMessage::GetNNetlinkAttribute (void)const
  18.126 +{
  18.127 +  return m_attributes.size ();
  18.128 +}
  18.129 +NetlinkAttribute
  18.130 +GeneralMessage::GetNetlinkAttribute (uint32_t index)const
  18.131 +{
  18.132 +  NS_ASSERT(index < GetNNetlinkAttribute ());
  18.133 +  return m_attributes[index];
  18.134 +}
  18.135 +
  18.136 +uint32_t
  18.137 +GeneralMessage::GetAttributeSerializedSize (void) const
  18.138 +{
  18.139 +  uint32_t size = 0;
  18.140 +
  18.141 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  18.142 +    {
  18.143 +      size += m_attributes[i].GetSerializedSize ();
  18.144 +    }
  18.145 +  return size;
  18.146 +}
  18.147 +bool
  18.148 +GeneralMessage::GetAttributeByType (NetlinkAttribute& attr, uint16_t type)
  18.149 +{
  18.150 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  18.151 +    {
  18.152 +      if (type == m_attributes[i].GetAttrType ())
  18.153 +        {
  18.154 +          attr = m_attributes[i];
  18.155 +          return true;
  18.156 +        }
  18.157 +    }
  18.158 +  return false;  
  18.159 +}
  18.160 +void
  18.161 +GeneralMessage::AppendAttribute (NetlinkAttribute v)
  18.162 +{
  18.163 +  m_attributes.push_back (v);
  18.164 +}
  18.165 +
  18.166 +void
  18.167 +GeneralMessage::SerializeAttribute (Buffer::Iterator& start) const
  18.168 +{
  18.169 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  18.170 +    {
  18.171 +      m_attributes[i].Serialize (start);
  18.172 +    }
  18.173 +}
  18.174 +
  18.175 +void
  18.176 +GeneralMessage::PrintAttribute (std::ostream &os) const
  18.177 +{
  18.178 +  for (uint32_t i = 0; i < m_attributes.size (); i ++)
  18.179 +    {
  18.180 +      os << " ----Attribute (" << i << "):";
  18.181 +      m_attributes[i].Print(os);
  18.182 +    }
  18.183 +}
  18.184 +
  18.185 +/***********************************************************************************
  18.186 +* \ InterfaceInfoMessage
  18.187 +***********************************************************************************/
  18.188 +InterfaceInfoMessage::InterfaceInfoMessage ()
  18.189 +  : m_reserved (0),
  18.190 +    m_deviceType (0),
  18.191 +    m_interfaceIndex(0),
  18.192 +    m_deviceFlags (0),
  18.193 +    m_changeMask (0)
  18.194 +{
  18.195 +  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  18.196 +  m_attributeTypes[IFL_A_UNSPEC] = UNSPEC;
  18.197 +  m_attributeTypes[IFL_A_ADDRESS] = ADDRESS;
  18.198 +  m_attributeTypes[IFL_A_BROADCAST] = ADDRESS;
  18.199 +  m_attributeTypes[IFL_A_IFNAME] = STRING;
  18.200 +  m_attributeTypes[IFL_A_MTU] = U32;
  18.201 +  m_attributeTypes[IFL_A_LINK] = U32;
  18.202 +  m_attributeTypes[IFL_A_QDISC] = U8;
  18.203 +  m_attributeTypes[IFL_A_STATS] = UNSPEC;
  18.204 +  m_attributeTypes[IFL_A_COST] = UNSPEC;
  18.205 +}
  18.206 +InterfaceInfoMessage::~InterfaceInfoMessage ()
  18.207 +{}
  18.208 +void
  18.209 +InterfaceInfoMessage::SetDeviceType (uint16_t type)
  18.210 +{
  18.211 +  m_deviceType = type;
  18.212 +}
  18.213 +void
  18.214 +InterfaceInfoMessage::SetInterfaceIndex (int32_t index)
  18.215 +{
  18.216 +  m_interfaceIndex = index;
  18.217 +}
  18.218 +void
  18.219 +InterfaceInfoMessage::SetDeviceFlags (uint32_t flags)
  18.220 +{
  18.221 +  m_deviceFlags = flags;
  18.222 +}
  18.223 +void
  18.224 +InterfaceInfoMessage::SetChangeMask (uint32_t mask)
  18.225 +{
  18.226 +  m_changeMask = mask;
  18.227 +}
  18.228 +uint16_t
  18.229 +InterfaceInfoMessage::GetDeviceType (void) const
  18.230 +{
  18.231 +  return m_deviceType;
  18.232 +}
  18.233 +int32_t
  18.234 +InterfaceInfoMessage::GetInterfaceIndex (void) const
  18.235 +{
  18.236 +  return m_interfaceIndex;
  18.237 +}
  18.238 +uint32_t
  18.239 +InterfaceInfoMessage::GetDeviceFlags (void) const
  18.240 +{
  18.241 +  return m_deviceFlags;
  18.242 +}
  18.243 +uint32_t
  18.244 +InterfaceInfoMessage::GetChangeMask (void) const
  18.245 +{
  18.246 +  return m_changeMask;
  18.247 +}
  18.248 +TypeId 
  18.249 +InterfaceInfoMessage::GetTypeId (void)
  18.250 +{
  18.251 +  static TypeId tid = TypeId ("ns3::InterfaceInfoMessage")
  18.252 +    .SetParent<GeneralMessage> ()
  18.253 +    .AddConstructor<InterfaceInfoMessage> ()
  18.254 +    ;
  18.255 +  return tid;
  18.256 +}
  18.257 +TypeId 
  18.258 +InterfaceInfoMessage::GetInstanceTypeId (void) const
  18.259 +{
  18.260 +  return GetTypeId ();
  18.261 +}
  18.262 +void 
  18.263 +InterfaceInfoMessage::Print (std::ostream &os) const
  18.264 +{  
  18.265 +  os << " ----InterfaceInfoMessage ("
  18.266 +     << "deviceType: " << m_deviceType << " "
  18.267 +     << "interfaceIndex: " << m_interfaceIndex << " "
  18.268 +     << "deviceFlags: " << m_deviceFlags << " "
  18.269 +     << "changeMask: " << m_changeMask << ")" ;
  18.270 +  PrintAttribute (os);
  18.271 +}
  18.272 +uint32_t 
  18.273 +InterfaceInfoMessage::GetSerializedSize (void) const
  18.274 +{
  18.275 +  return NETLINK_INTERFACE_SIZE + GetAttributeSerializedSize ();
  18.276 +}
  18.277 +
  18.278 +void
  18.279 +InterfaceInfoMessage::Serialize (Buffer::Iterator& start) const
  18.280 +{
  18.281 +  start.WriteU8 (m_family);
  18.282 +  start.WriteU8 (m_reserved);
  18.283 +  start.WriteU16 (m_deviceType);
  18.284 +  start.WriteU32 (m_interfaceIndex);
  18.285 +  start.WriteU32 (m_deviceFlags);
  18.286 +  start.WriteU32 (m_changeMask);
  18.287 +
  18.288 +  SerializeAttribute (start);
  18.289 +}
  18.290 +uint32_t
  18.291 +InterfaceInfoMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  18.292 +{
  18.293 +  m_family = start.ReadU8 ();
  18.294 +  m_reserved = start.ReadU8 ();
  18.295 +  m_deviceType = start.ReadU16 ();
  18.296 +  m_interfaceIndex = start.ReadU32 ();
  18.297 +  m_deviceFlags = start.ReadU32 ();
  18.298 +  m_changeMask = start.ReadU32 ();
  18.299 +
  18.300 +  len -= NETLINK_INTERFACE_SIZE;
  18.301 +
  18.302 +  while (len)
  18.303 +    {
  18.304 +      NetlinkAttribute attr;
  18.305 +
  18.306 +      len -= attr.Deserialize (start, m_attributeTypes);
  18.307 +      m_attributes.push_back (attr);
  18.308 +    }
  18.309 +
  18.310 +  return GetSerializedSize ();
  18.311 +}
  18.312 +
  18.313 +
  18.314 +
  18.315 +/***********************************************************************************
  18.316 +* \InterfaceAddressMessage
  18.317 +***********************************************************************************/
  18.318 +InterfaceAddressMessage::InterfaceAddressMessage ()
  18.319 +  : m_length (0),
  18.320 +    m_flags (0),
  18.321 +    m_scope (0),
  18.322 +    m_index(0)
  18.323 +{
  18.324 +  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  18.325 +  m_attributeTypes[IF_A_UNSPEC] = UNSPEC;
  18.326 +  m_attributeTypes[IF_A_ADDRESS] = ADDRESS;
  18.327 +  m_attributeTypes[IF_A_LOCAL] = ADDRESS;
  18.328 +  m_attributeTypes[IF_A_LABEL] = STRING;
  18.329 +  m_attributeTypes[IF_A_BROADCAST] = ADDRESS;
  18.330 +  m_attributeTypes[IF_A_ANYCAST] = ADDRESS;
  18.331 +  m_attributeTypes[IF_A_CACHEINFO] = UNSPEC;
  18.332 +  m_attributeTypes[IF_A_MULTICAST] = ADDRESS;
  18.333 +}
  18.334 +InterfaceAddressMessage::~InterfaceAddressMessage ()
  18.335 +{
  18.336 +}
  18.337 +void
  18.338 +InterfaceAddressMessage::SetFamily (uint8_t family)
  18.339 +{
  18.340 +  m_family = family;
  18.341 +}
  18.342 +void
  18.343 +InterfaceAddressMessage::SetLength (uint8_t length)
  18.344 +{
  18.345 +  m_length = length;
  18.346 +}
  18.347 +void
  18.348 +InterfaceAddressMessage::SetFlags (uint8_t flags)
  18.349 +{
  18.350 +  m_flags = flags;
  18.351 +}
  18.352 +void
  18.353 +InterfaceAddressMessage::SetScope (uint8_t scope)
  18.354 +{
  18.355 +  m_scope = scope;
  18.356 +}
  18.357 +void
  18.358 +InterfaceAddressMessage::SetInterfaceIndex (int32_t index)
  18.359 +{
  18.360 +  m_index = index;
  18.361 +}
  18.362 +
  18.363 +uint8_t
  18.364 +InterfaceAddressMessage::GetFamily (void) const
  18.365 +{
  18.366 +  return m_family;
  18.367 +}
  18.368 +uint8_t
  18.369 +InterfaceAddressMessage::GetLength (void) const
  18.370 +{
  18.371 +  return m_length;
  18.372 +}
  18.373 +uint8_t
  18.374 +InterfaceAddressMessage::GetFlags (void) const
  18.375 +{
  18.376 +  return m_flags;
  18.377 +}
  18.378 +uint8_t
  18.379 +InterfaceAddressMessage::GetScope (void) const
  18.380 +{
  18.381 +  return m_scope;
  18.382 +}
  18.383 +int32_t
  18.384 +InterfaceAddressMessage::GetInterfaceIndex (void) const
  18.385 +{
  18.386 +  return m_index;
  18.387 +}
  18.388 +
  18.389 +TypeId 
  18.390 +InterfaceAddressMessage::GetTypeId (void)
  18.391 +{
  18.392 +  static TypeId tid = TypeId ("ns3::InterfaceAddressMessage")
  18.393 +    .SetParent<GeneralMessage> ()
  18.394 +    .AddConstructor<InterfaceAddressMessage> ()
  18.395 +    ;
  18.396 +  return tid;
  18.397 +}
  18.398 +TypeId 
  18.399 +InterfaceAddressMessage::GetInstanceTypeId (void) const
  18.400 +{
  18.401 +  return GetTypeId ();
  18.402 +}
  18.403 +void 
  18.404 +InterfaceAddressMessage::Print (std::ostream &os) const
  18.405 +{  
  18.406 +  os << " ----InterfaceAddressMessage ("
  18.407 +     << "family: " << (uint32_t)m_family << " "
  18.408 +     << "length: " << (uint32_t)m_length << " "
  18.409 +     << "flags: " << (uint32_t)m_flags << " "
  18.410 +     << "scope: " << (uint32_t)m_scope << " "
  18.411 +     << "index: " << m_index << ")";
  18.412 +  PrintAttribute (os);
  18.413 +}
  18.414 +uint32_t 
  18.415 +InterfaceAddressMessage::GetSerializedSize (void) const
  18.416 +{
  18.417 +  return NETLINK_ADDRESS_SIZE + GetAttributeSerializedSize ();
  18.418 +}
  18.419 +
  18.420 +void
  18.421 +InterfaceAddressMessage::Serialize (Buffer::Iterator& start) const
  18.422 +{
  18.423 +  start.WriteU8 (m_family);
  18.424 +  start.WriteU8 (m_length);
  18.425 +  start.WriteU8 (m_flags);
  18.426 +  start.WriteU8 (m_scope);
  18.427 +  start.WriteU32 (m_index);
  18.428 +
  18.429 +  SerializeAttribute(start);
  18.430 +}
  18.431 +
  18.432 +uint32_t
  18.433 +InterfaceAddressMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  18.434 +{
  18.435 +  m_family = start.ReadU8 ();
  18.436 +  m_length = start.ReadU8 ();
  18.437 +  m_flags = start.ReadU8 ();
  18.438 +  m_scope = start.ReadU8 ();
  18.439 +  m_index = start.ReadU32 ();
  18.440 +
  18.441 +  len -= NETLINK_ADDRESS_SIZE;
  18.442 +
  18.443 +  while (len)
  18.444 +    {
  18.445 +      NetlinkAttribute attr;
  18.446 +
  18.447 +      len -= attr.Deserialize (start, m_attributeTypes);
  18.448 +      m_attributes.push_back (attr);
  18.449 +    }
  18.450 +
  18.451 +  return GetSerializedSize ();
  18.452 +}
  18.453 +
  18.454 +
  18.455 +
  18.456 +/***********************************************************************************
  18.457 +* \ RouteMessage
  18.458 +***********************************************************************************/
  18.459 +RouteMessage::RouteMessage ()
  18.460 +  : m_dstLen (0),
  18.461 +    m_srcLen (0),
  18.462 +    m_tos (0),
  18.463 +    m_tableId (0),
  18.464 +    m_protocol(0),
  18.465 +    m_scope (0),
  18.466 +    m_type (0),
  18.467 +    m_flags (0)
  18.468 +{
  18.469 +  memset ((void*)m_attributeTypes, 0, sizeof (m_attributeTypes));
  18.470 +  m_attributeTypes[RT_A_UNSPEC] = UNSPEC;
  18.471 +  m_attributeTypes[RT_A_DST] = ADDRESS;
  18.472 +  m_attributeTypes[RT_A_SRC] = ADDRESS;
  18.473 +  m_attributeTypes[RT_A_IIF] = U32;
  18.474 +  m_attributeTypes[RT_A_OIF] = U32;
  18.475 +  m_attributeTypes[RT_A_GATEWAY] = ADDRESS;
  18.476 +  m_attributeTypes[RT_A_PRIORITY] = U8;
  18.477 +  m_attributeTypes[RT_A_PREFSRC] = ADDRESS;
  18.478 +  m_attributeTypes[RT_A_METRICS] = UNSPEC;
  18.479 +  //others default value UNSPEC
  18.480 +}
  18.481 +RouteMessage::~RouteMessage ()
  18.482 +{}
  18.483 +
  18.484 +void
  18.485 +RouteMessage::SetFamily (uint8_t v)
  18.486 +{
  18.487 +  m_family = v;
  18.488 +}
  18.489 +void
  18.490 +RouteMessage::SetDstLength (uint8_t v)
  18.491 +{
  18.492 +  m_dstLen = v;
  18.493 +}
  18.494 +void
  18.495 +RouteMessage::SetSrcLength (uint8_t v)
  18.496 +{
  18.497 +  m_srcLen = v;
  18.498 +}
  18.499 +void
  18.500 +RouteMessage::SetTos (uint8_t v)
  18.501 +{
  18.502 +  m_tos = v;
  18.503 +}
  18.504 +void
  18.505 +RouteMessage::SetTableId (uint8_t v)
  18.506 +{
  18.507 +  m_tableId = v;
  18.508 +}
  18.509 +void
  18.510 +RouteMessage::SetProtocol (uint8_t v)
  18.511 +{
  18.512 +  m_protocol = v;
  18.513 +}
  18.514 +void
  18.515 +RouteMessage::SetScope (uint8_t v)
  18.516 +{
  18.517 +  m_scope = v;
  18.518 +}
  18.519 +void
  18.520 +RouteMessage::SetType (uint8_t v)
  18.521 +{
  18.522 +  m_type = v;
  18.523 +}
  18.524 +void
  18.525 +RouteMessage::SetFlags (uint32_t v)
  18.526 +{
  18.527 +  m_flags = v;
  18.528 +}
  18.529 +uint8_t
  18.530 +RouteMessage::GetFamily (void) const
  18.531 +{
  18.532 +  return m_family;
  18.533 +}
  18.534 +uint8_t
  18.535 +RouteMessage::GetDstLength (void) const
  18.536 +{
  18.537 +  return m_dstLen;
  18.538 +}
  18.539 +uint8_t
  18.540 +RouteMessage::GetSrcLength (void) const
  18.541 +{
  18.542 +  return m_srcLen;
  18.543 +}
  18.544 +uint8_t
  18.545 +RouteMessage::GetTos (void) const
  18.546 +{
  18.547 +  return m_tos;
  18.548 +}
  18.549 +uint8_t
  18.550 +RouteMessage::GetTableId (void) const
  18.551 +{
  18.552 +  return m_tableId;
  18.553 +}
  18.554 +uint8_t
  18.555 +RouteMessage::GetProtocol (void) const
  18.556 +{
  18.557 +  return m_protocol;
  18.558 +}
  18.559 +uint8_t
  18.560 +RouteMessage::GetType (void) const
  18.561 +{
  18.562 +  return m_type;
  18.563 +}
  18.564 +uint8_t
  18.565 +RouteMessage::GetScope (void) const
  18.566 +{
  18.567 +  return m_scope;
  18.568 +}
  18.569 +uint32_t
  18.570 +RouteMessage::GetFlags (void) const
  18.571 +{
  18.572 +  return m_flags;
  18.573 +}
  18.574 +
  18.575 +TypeId 
  18.576 +RouteMessage::GetTypeId (void)
  18.577 +{
  18.578 +  static TypeId tid = TypeId ("ns3::RouteMessage")
  18.579 +    .SetParent<GeneralMessage> ()
  18.580 +    .AddConstructor<RouteMessage> ()
  18.581 +    ;
  18.582 +  return tid;
  18.583 +}
  18.584 +TypeId 
  18.585 +RouteMessage::GetInstanceTypeId (void) const
  18.586 +{
  18.587 +  return GetTypeId ();
  18.588 +}
  18.589 +void 
  18.590 +RouteMessage::Print (std::ostream &os) const
  18.591 +{  
  18.592 +  os << " ----RouteMessage ("
  18.593 +     << "family: " << (uint32_t)m_family << " "
  18.594 +     << "dstLen: " << (uint32_t)m_dstLen << " "
  18.595 +     << "srcLen: " << (uint32_t)m_srcLen << " "
  18.596 +     << "tos: " << (uint32_t)m_tos << " "
  18.597 +     << "tableId: " << (uint32_t)m_tableId << " "
  18.598 +     << "protocol: " << (uint32_t)m_protocol << " "
  18.599 +     << "scope: " << (uint32_t)m_scope << " "
  18.600 +     << "type: " << (uint32_t)m_type << " "
  18.601 +     << "flags: " << m_flags<< ")" ;
  18.602 +  PrintAttribute (os);
  18.603 +}
  18.604 +uint32_t 
  18.605 +RouteMessage::GetSerializedSize (void) const
  18.606 +{
  18.607 +  return NETLINK_ROUTE_SIZE + GetAttributeSerializedSize ();
  18.608 +}
  18.609 +
  18.610 +void
  18.611 +RouteMessage::Serialize (Buffer::Iterator& start) const
  18.612 +{
  18.613 +  start.WriteU8 (m_family);
  18.614 +  start.WriteU8 (m_dstLen);
  18.615 +  start.WriteU8 (m_srcLen);
  18.616 +  start.WriteU8 (m_tos);
  18.617 +  start.WriteU8 (m_tableId);
  18.618 +  start.WriteU8 (m_protocol);
  18.619 +  start.WriteU8 (m_scope);
  18.620 +  start.WriteU8 (m_type);
  18.621 +  start.WriteU32 (m_flags);
  18.622 +
  18.623 +  SerializeAttribute (start);
  18.624 +}
  18.625 +uint32_t
  18.626 +RouteMessage::Deserialize (Buffer::Iterator& start, uint32_t len)
  18.627 +{
  18.628 +  m_family = start.ReadU8 ();
  18.629 +  m_dstLen = start.ReadU8 ();
  18.630 +  m_srcLen = start.ReadU8 ();
  18.631 +  m_tos = start.ReadU8 ();
  18.632 +  m_tableId = start.ReadU8 ();
  18.633 +  m_protocol = start.ReadU8 ();
  18.634 +  m_scope = start.ReadU8 ();
  18.635 +  m_type = start.ReadU8 ();
  18.636 +  m_flags = start.ReadU32 ();
  18.637 +
  18.638 +  len -= NETLINK_ROUTE_SIZE;
  18.639 +
  18.640 +  while (len)
  18.641 +    {
  18.642 +      NetlinkAttribute attr;
  18.643 +
  18.644 +      len -= attr.Deserialize (start, m_attributeTypes);
  18.645 +      m_attributes.push_back (attr);
  18.646 +    }
  18.647 +
  18.648 +  return GetSerializedSize ();
  18.649 +}
  18.650 +}; // namespace ns3
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/netlink/netlink-message-route.h	Thu May 05 09:28:21 2011 +0200
    19.3 @@ -0,0 +1,388 @@
    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_ROUTE_H
   19.26 +#define NETLINK_MESSAGE_ROUTE_H
   19.27 +
   19.28 +#include "ns3/object-base.h"
   19.29 +#include "ns3/address.h"
   19.30 +#include "netlink-attribute.h"
   19.31 +#include <string>
   19.32 +
   19.33 +namespace ns3 {
   19.34 +
   19.35 +/*
   19.36 +* this file define some netlink message of NETLINK_ROUTE protocol,
   19.37 +* there are mainly three types:interface address, interface info, route entry
   19.38 +* just implemented them for quagga porting.
   19.39 +*/
   19.40 +  
   19.41 +
   19.42 +
   19.43 +/**
   19.44 +* \Types of messages,here we only define the route message types quagga used
   19.45 +*/
   19.46 +enum NetlinkRtmType_e {
   19.47 +  NETLINK_RTM_BASE = 16,
   19.48 +
   19.49 +  NETLINK_RTM_NEWLINK = 16,
   19.50 +  NETLINK_RTM_DELLINK,
   19.51 +  NETLINK_RTM_GETLINK,
   19.52 +  NETLINK_RTM_SETLINK,
   19.53 +
   19.54 +  NETLINK_RTM_NEWADDR = 20,
   19.55 +  NETLINK_RTM_DELADDR,
   19.56 +  NETLINK_RTM_GETADDR,
   19.57 +
   19.58 +  NETLINK_RTM_NEWROUTE = 24,
   19.59 +  NETLINK_RTM_DELROUTE,
   19.60 +  NETLINK_RTM_GETROUTE,
   19.61 +
   19.62 +  NETLINK_RTM_MAX,
   19.63 +};  
   19.64 +
   19.65 +/**
   19.66 +* \Types of netlink groups,here we only define types quagga used
   19.67 +*/
   19.68 +enum NetlinkRtmGroup_e {
   19.69 +  NETLINK_RTM_GRP_LINK = 1,
   19.70 +  NETLINK_RTM_GRP_IPV4_IFADDR = 0x10,
   19.71 +  NETLINK_RTM_GRP_IPV4_ROUTE = 0x40,
   19.72 +  RTMGRP_IPV6_IFADDR = 0x100,
   19.73 +  RTMGRP_IPV6_ROUTE = 0x400,
   19.74 +};
   19.75 +
   19.76 +class NetlinkPayload :public ObjectBase
   19.77 +{
   19.78 +public:
   19.79 +  static TypeId GetTypeId (void);
   19.80 +  virtual TypeId GetInstanceTypeId (void) const = 0;
   19.81 +  virtual void Serialize (Buffer::Iterator& start) const = 0;
   19.82 +  virtual void Print (std::ostream &os) const = 0;
   19.83 +  virtual uint32_t GetSerializedSize (void) const = 0;
   19.84 +};
   19.85 +
   19.86 +/***
   19.87 + General form of address family dependent message.
   19.88 +
   19.89 +  struct rtgenmsg
   19.90 +  {
   19.91 +    unsigned char		rtgen_family;
   19.92 +  };
   19.93 +**/
   19.94 +
   19.95 +class GeneralMessage : public NetlinkPayload
   19.96 +{
   19.97 +public:
   19.98 +  GeneralMessage ();
   19.99 +  virtual ~GeneralMessage ();
  19.100 +
  19.101 +  static TypeId GetTypeId (void);
  19.102 +  virtual TypeId GetInstanceTypeId (void) const;
  19.103 +  virtual void Serialize (Buffer::Iterator& start) const;
  19.104 +  virtual uint32_t Deserialize (Buffer::Iterator& start);
  19.105 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  19.106 +  virtual void Print (std::ostream &os) const;
  19.107 +  virtual uint32_t GetSerializedSize (void) const;
  19.108 +
  19.109 +  
  19.110 +  virtual uint32_t GetNNetlinkAttribute (void)const;
  19.111 +  virtual NetlinkAttribute GetNetlinkAttribute (uint32_t index)const;
  19.112 +  virtual void AppendAttribute (NetlinkAttribute v);
  19.113 +  virtual void SerializeAttribute (Buffer::Iterator& start) const;
  19.114 +  virtual void PrintAttribute (std::ostream &os) const;
  19.115 +  virtual uint32_t GetAttributeSerializedSize (void) const;
  19.116 +  virtual bool GetAttributeByType (NetlinkAttribute& attr, uint16_t type);
  19.117 +
  19.118 +
  19.119 +  void SetFamily (uint8_t v);
  19.120 +  uint8_t GetFamily (void) const;
  19.121 +
  19.122 +private:
  19.123 +  static const int NETLINK_GENMSG_SIZE = 1; /* size of the struct rtgenmsg */  
  19.124 +protected:
  19.125 +  uint8_t m_family;   //always set to AF_UNSPEC
  19.126 +  //attribute can exist or not
  19.127 +  std::vector<NetlinkAttribute> m_attributes;
  19.128 +};
  19.129 +
  19.130 +
  19.131 +
  19.132 +/**
  19.133 +* \brief Link layer specific messages
  19.134 +*
  19.135 +* struct ifinfomsg
  19.136 +* passes link level specific information, not dependent
  19.137 +* on network protocol.
  19.138 +*
  19.139 +  struct ifinfomsg
  19.140 +  {
  19.141 +    unsigned char	ifi_family;
  19.142 +    unsigned char	__ifi_pad;
  19.143 +    unsigned short	ifi_type;
  19.144 +    int		ifi_index;	
  19.145 +    unsigned	ifi_flags;
  19.146 +    unsigned	ifi_change;
  19.147 +  };
  19.148 +*/
  19.149 +class InterfaceInfoMessage : public GeneralMessage
  19.150 +{
  19.151 +public:
  19.152 +  InterfaceInfoMessage ();
  19.153 +  virtual ~InterfaceInfoMessage ();
  19.154 +
  19.155 +  static TypeId GetTypeId (void);
  19.156 +  virtual TypeId GetInstanceTypeId (void) const;
  19.157 +  virtual void Serialize (Buffer::Iterator& start) const;
  19.158 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  19.159 +  virtual void Print (std::ostream &os) const;
  19.160 +  virtual uint32_t GetSerializedSize (void) const;
  19.161 +
  19.162 +  enum IflAttr_e {
  19.163 +    IFL_A_UNSPEC,
  19.164 +    IFL_A_ADDRESS,
  19.165 +    IFL_A_BROADCAST,
  19.166 +    IFL_A_IFNAME,
  19.167 +    IFL_A_MTU,
  19.168 +    IFL_A_LINK,
  19.169 +    IFL_A_QDISC,
  19.170 +    IFL_A_STATS,
  19.171 +    IFL_A_COST,
  19.172 +    IFL_A_PRIORITY,
  19.173 +    IFL_A_MASTER,
  19.174 +    IFL_A_WIRELESS,		
  19.175 +    IFL_A_PROTINFO,
  19.176 +    IFL_A_TXQLEN,
  19.177 +    IFL_A_MAP,
  19.178 +    IFL_A_WEIGHT,
  19.179 +    IFL_A_OPERSTATE,
  19.180 +    IFL_A_LINKMODE,
  19.181 +    IFL_A_MAX,
  19.182 +  };
  19.183 +
  19.184 +  enum Type_e {
  19.185 +    UP = 1,
  19.186 +    BROADCAST = 2,
  19.187 +    DBG = 4,
  19.188 +  };
  19.189 +
  19.190 +  void SetDeviceType (uint16_t type);
  19.191 +  void SetInterfaceIndex (int32_t index);
  19.192 +  void SetDeviceFlags (uint32_t index);
  19.193 +  void SetChangeMask (uint32_t mask);
  19.194 +
  19.195 +  uint16_t GetDeviceType (void) const;
  19.196 +  int32_t GetInterfaceIndex (void) const;
  19.197 +  uint32_t GetDeviceFlags (void) const;
  19.198 +  uint32_t GetChangeMask (void) const;
  19.199 +private:
  19.200 +  static const int NETLINK_INTERFACE_SIZE = 16; /* size of the struct ifinfomsg */
  19.201 +  uint8_t m_reserved; //not used
  19.202 +  uint16_t m_deviceType;
  19.203 +  int32_t m_interfaceIndex;
  19.204 +  uint32_t m_deviceFlags;
  19.205 +  uint32_t m_changeMask;
  19.206 +  NetlinkAttributeValueType m_attributeTypes[IFL_A_MAX];
  19.207 +};
  19.208 +
  19.209 +
  19.210 +
  19.211 +
  19.212 +/**
  19.213 +* \brief Interface address.
  19.214 +*
  19.215 +  struct ifaddrmsg
  19.216 +  {
  19.217 +  unsigned char	ifa_family;
  19.218 +  unsigned char	ifa_prefixlen;
  19.219 +  unsigned char	ifa_flags;
  19.220 +  unsigned char	ifa_scope;
  19.221 +  int		ifa_index;
  19.222 +  };
  19.223 +*/
  19.224 +
  19.225 +class InterfaceAddressMessage : public GeneralMessage
  19.226 +{
  19.227 +public:
  19.228 +  InterfaceAddressMessage ();
  19.229 +  virtual ~InterfaceAddressMessage ();
  19.230 +
  19.231 +  static TypeId GetTypeId (void);
  19.232 +  virtual TypeId GetInstanceTypeId (void) const;
  19.233 +  virtual void Serialize (Buffer::Iterator& start) const;
  19.234 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  19.235 +  virtual void Print (std::ostream &os) const;
  19.236 +  virtual uint32_t GetSerializedSize (void) const;
  19.237 +
  19.238 +  enum IfAttr_e {
  19.239 +    IF_A_UNSPEC,
  19.240 +    IF_A_ADDRESS,
  19.241 +    IF_A_LOCAL,
  19.242 +    IF_A_LABEL,
  19.243 +    IF_A_BROADCAST,
  19.244 +    IF_A_ANYCAST,
  19.245 +    IF_A_CACHEINFO,
  19.246 +    IF_A_MULTICAST,
  19.247 +    IF_A_MAX
  19.248 +  };
  19.249 +
  19.250 +  enum {
  19.251 +    F_SECONDARY = 0x01,
  19.252 +    F_PERMANENT = 0x80,
  19.253 +    F_DEPRECATED = 0x20,
  19.254 +    F_TENTATIVE = 0x40
  19.255 +  };
  19.256 +  enum {
  19.257 +    SCOPE_UNIVERSE = 0,
  19.258 +    SCOPE_SITE = 200,
  19.259 +    SCOPE_LINK = 253,
  19.260 +    SCOPE_HOST = 254
  19.261 +  };
  19.262 +
  19.263 +
  19.264 +  void SetFamily (uint8_t family);
  19.265 +  void SetLength (uint8_t length);
  19.266 +  void SetFlags (uint8_t flags);
  19.267 +  void SetScope (uint8_t scope);
  19.268 +  void SetInterfaceIndex (int32_t index);
  19.269 +
  19.270 +  uint8_t GetFamily (void) const;
  19.271 +  uint8_t GetLength (void) const;
  19.272 +  uint8_t GetFlags (void) const;
  19.273 +  uint8_t GetScope (void) const;
  19.274 +  int32_t GetInterfaceIndex (void) const;
  19.275 +
  19.276 +private:
  19.277 +  static const int NETLINK_ADDRESS_SIZE = 8; /* size of the struct ifaddrmsg */
  19.278 +  uint8_t m_length;
  19.279 +  uint8_t m_flags;
  19.280 +  uint8_t m_scope;
  19.281 +  int32_t m_index;
  19.282 +  NetlinkAttributeValueType m_attributeTypes[IF_A_MAX];
  19.283 +};
  19.284 +
  19.285 +
  19.286 +/**
  19.287 +* \brief Definitions used in routing table administration.
  19.288 +*
  19.289 +  struct rtmsg
  19.290 +  {
  19.291 +    unsigned char		rtm_family;
  19.292 +    unsigned char		rtm_dst_len;
  19.293 +    unsigned char		rtm_src_len;
  19.294 +    unsigned char		rtm_tos;
  19.295 +
  19.296 +    unsigned char		rtm_table;	// Routing table id 
  19.297 +    unsigned char		rtm_protocol;	//Routing protocol; 
  19.298 +    unsigned char		rtm_scope;	
  19.299 +    unsigned char		rtm_type;	
  19.300 +
  19.301 +    unsigned		rtm_flags;
  19.302 +  };
  19.303 +*/
  19.304 +
  19.305 +class RouteMessage : public GeneralMessage
  19.306 +{
  19.307 +public:
  19.308 +  RouteMessage ();
  19.309 +  virtual ~RouteMessage ();
  19.310 +
  19.311 +  static TypeId GetTypeId (void);
  19.312 +  virtual TypeId GetInstanceTypeId (void) const;
  19.313 +  virtual void Serialize (Buffer::Iterator& start) const;
  19.314 +  virtual uint32_t Deserialize (Buffer::Iterator& start, uint32_t len);
  19.315 +  virtual void Print (std::ostream &os) const;
  19.316 +  virtual uint32_t GetSerializedSize (void) const;
  19.317 +
  19.318 +  uint8_t GetFamily (void) const;
  19.319 +  uint8_t GetDstLength (void) const;
  19.320 +  uint8_t GetSrcLength (void) const;
  19.321 +  uint8_t GetTos (void) const;
  19.322 +  uint8_t GetTableId (void) const;
  19.323 +  uint8_t GetProtocol(void) const;
  19.324 +  uint8_t GetType (void) const;
  19.325 +  uint8_t GetScope (void) const;
  19.326 +  uint32_t GetFlags (void) const;
  19.327 +  void SetFamily (uint8_t v);
  19.328 +  void SetDstLength (uint8_t v);
  19.329 +  void SetSrcLength (uint8_t v);
  19.330 +  void SetTos (uint8_t v);
  19.331 +  void SetTableId (uint8_t v);
  19.332 +  void SetProtocol (uint8_t v);
  19.333 +  void SetScope (uint8_t v);
  19.334 +  void SetType (uint8_t v);
  19.335 +  void SetFlags (uint32_t v);
  19.336 +
  19.337 +  enum RtProtocol_e {
  19.338 +    RT_PROT_UNSPEC = 0,
  19.339 +  };
  19.340 +
  19.341 +  enum RtFlags_e {
  19.342 +    RT_F_CLONED = 0x200,
  19.343 +  };
  19.344 +
  19.345 +  enum RtScope_e {
  19.346 +    RT_SCOPE_UNIVERSE = 0,
  19.347 +    RT_SCOPE_LINK = 253,
  19.348 +  };
  19.349 +
  19.350 +  enum RtClass_e {
  19.351 +    RT_TABLE_UNSPEC = 0,
  19.352 +    RT_TABLE_MAIN = 254,
  19.353 +  };
  19.354 +
  19.355 +  enum RtAttr_e {
  19.356 +    RT_A_UNSPEC,
  19.357 +    RT_A_DST,
  19.358 +    RT_A_SRC,
  19.359 +    RT_A_IIF,
  19.360 +    RT_A_OIF,
  19.361 +    RT_A_GATEWAY,
  19.362 +    RT_A_PRIORITY,
  19.363 +    RT_A_PREFSRC,
  19.364 +    RT_A_METRICS,
  19.365 +    RT_A_MULTIPATH,
  19.366 +    RT_A_PROTOINFO,
  19.367 +    RT_A_FLOW,
  19.368 +    RT_A_CACHEINFO,
  19.369 +    RT_A_SESSION,
  19.370 +    RT_A_MP_ALGO,
  19.371 +    RT_A_TABLE,
  19.372 +    RT_A_MAX
  19.373 +  };
  19.374 +
  19.375 +
  19.376 +private:
  19.377 +  static const int NETLINK_ROUTE_SIZE = 12; /* size of the struct rtmsg */
  19.378 +  uint8_t m_dstLen;
  19.379 +  uint8_t m_srcLen;
  19.380 +  uint8_t m_tos;
  19.381 +  uint8_t m_tableId;
  19.382 +  uint8_t m_protocol;
  19.383 +  uint8_t m_scope;
  19.384 +  uint8_t m_type;
  19.385 +  uint32_t m_flags;
  19.386 +  NetlinkAttributeValueType m_attributeTypes[RT_A_MAX];
  19.387 +};
  19.388 +
  19.389 +}; // namespace ns3
  19.390 +
  19.391 +#endif /* NETLINK_MESSAGE_ROUTE_H */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/netlink/netlink-message.cc	Thu May 05 09:28:21 2011 +0200
    20.3 @@ -0,0 +1,672 @@
    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-message.h"
   20.26 +#include "ns3/address-utils.h"
   20.27 +#include "ns3/log.h"
   20.28 +
   20.29 +NS_LOG_COMPONENT_DEFINE ("NetlinkMessage");
   20.30 +
   20.31 +namespace ns3 {
   20.32 +
   20.33 +/***********************************************************************************
   20.34 +* \ NetlinkMessageHeader
   20.35 +***********************************************************************************/
   20.36 +NS_OBJECT_ENSURE_REGISTERED (NetlinkMessageHeader);
   20.37 +NS_OBJECT_ENSURE_REGISTERED (NetlinkMessage);
   20.38 +
   20.39 +NetlinkMessageHeader::NetlinkMessageHeader ()
   20.40 +  : m_nlmsgLen (16),
   20.41 +    m_nlmsgType (0),
   20.42 +    m_nlmsgFlags (0),
   20.43 +    m_nlmsgSeq (0),
   20.44 +    m_nlmsgPid (0)
   20.45 +{}
   20.46 +
   20.47 +NetlinkMessageHeader::NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid)
   20.48 +  : m_nlmsgLen (16),
   20.49 +    m_nlmsgType (type),
   20.50 +    m_nlmsgFlags (flags),
   20.51 +    m_nlmsgSeq (seq),
   20.52 +    m_nlmsgPid (pid)
   20.53 +{}
   20.54 +
   20.55 +void
   20.56 +NetlinkMessageHeader::SetMsgLen (uint32_t v)
   20.57 +{
   20.58 +  m_nlmsgLen = v;
   20.59 +}
   20.60 +void
   20.61 +NetlinkMessageHeader::SetMsgFlags (uint16_t v)
   20.62 +{
   20.63 +  m_nlmsgFlags = v;
   20.64 +}
   20.65 +void
   20.66 +NetlinkMessageHeader::SetMsgType (uint16_t v)
   20.67 +{
   20.68 +  m_nlmsgType = v;
   20.69 +}
   20.70 +void
   20.71 +NetlinkMessageHeader::SetMsgSeq (uint32_t v)
   20.72 +{
   20.73 +  m_nlmsgSeq = v;
   20.74 +}
   20.75 +void
   20.76 +NetlinkMessageHeader::SetMsgPid (uint32_t v)
   20.77 +{
   20.78 +  m_nlmsgPid = v;
   20.79 +}
   20.80 +uint16_t
   20.81 +NetlinkMessageHeader::GetMsgFlags (void) const
   20.82 +{
   20.83 +  return m_nlmsgFlags;
   20.84 +}
   20.85 +uint32_t 
   20.86 +NetlinkMessageHeader::GetMsgLen (void) const
   20.87 +{
   20.88 +  return m_nlmsgLen;
   20.89 +}
   20.90 +uint16_t 
   20.91 +NetlinkMessageHeader::GetMsgType (void) const
   20.92 +{
   20.93 +  return m_nlmsgType;
   20.94 +}
   20.95 +uint32_t
   20.96 +NetlinkMessageHeader::GetMsgSeq (void) const
   20.97 +{
   20.98 +  return m_nlmsgSeq;
   20.99 +}
  20.100 +uint32_t 
  20.101 +NetlinkMessageHeader::GetMsgPid (void) const
  20.102 +{
  20.103 +  return m_nlmsgPid;
  20.104 +}
  20.105 +uint32_t
  20.106 +NetlinkMessageHeader::GetHeaderSize ()
  20.107 +{
  20.108 +  return NETLINK_MSG_HEADER_SIZE;
  20.109 +}
  20.110 +uint32_t
  20.111 +NetlinkMessageHeader::GetPayloadSize (void) const
  20.112 +{
  20.113 +  return NETLINK_MSG_ALIGN (m_nlmsgLen - NETLINK_MSG_HEADER_SIZE);
  20.114 +}
  20.115 +
  20.116 +TypeId 
  20.117 +NetlinkMessageHeader::GetTypeId (void)
  20.118 +{
  20.119 +  static TypeId tid = TypeId ("ns3::NetlinkMessageHeader")
  20.120 +    .SetParent<Header> ()
  20.121 +    .AddConstructor<NetlinkMessageHeader> ()
  20.122 +    ;
  20.123 +  return tid;
  20.124 +}
  20.125 +TypeId 
  20.126 +NetlinkMessageHeader::GetInstanceTypeId (void) const
  20.127 +{
  20.128 +  return GetTypeId ();
  20.129 +}
  20.130 +void 
  20.131 +NetlinkMessageHeader::Print (std::ostream &os) const
  20.132 +{
  20.133 +  os << "NetlinkMessageHeader "
  20.134 +     << "len: " << m_nlmsgLen << " "
  20.135 +     << "flags: " << m_nlmsgFlags << " "
  20.136 +     << "type: " << m_nlmsgType << " "
  20.137 +     << "seq: " << m_nlmsgSeq << " "
  20.138 +     << "pid: " << m_nlmsgPid;
  20.139 +}
  20.140 +
  20.141 +uint32_t 
  20.142 +NetlinkMessageHeader::GetSerializedSize (void) const
  20.143 +{
  20.144 +  /* this is the size of an nlmsghdr payload. */
  20.145 +  return NETLINK_MSG_HEADER_SIZE;
  20.146 +}
  20.147 +
  20.148 +void
  20.149 +NetlinkMessageHeader::Serialize (Buffer::Iterator& start) const
  20.150 +{
  20.151 +  start.WriteU32 (m_nlmsgLen);
  20.152 +  start.WriteU16 (m_nlmsgType);
  20.153 +  start.WriteU16 (m_nlmsgFlags);
  20.154 +  start.WriteU32 (m_nlmsgSeq);
  20.155 +  start.WriteU32 (m_nlmsgPid);
  20.156 +}
  20.157 +
  20.158 +uint32_t
  20.159 +NetlinkMessageHeader::Deserialize (Buffer::Iterator& start)
  20.160 +{
  20.161 +  m_nlmsgLen = start.ReadU32 ();
  20.162 +  m_nlmsgType = start.ReadU16 ();
  20.163 +  m_nlmsgFlags = start.ReadU16 ();
  20.164 +  m_nlmsgSeq = start.ReadU32 ();
  20.165 +  m_nlmsgPid = start.ReadU32 ();
  20.166 +
  20.167 +  return GetSerializedSize ();
  20.168 +}
  20.169 +
  20.170 +
  20.171 +
  20.172 +
  20.173 +/***********************************************************************************
  20.174 +* \ NetlinkMessageError
  20.175 +***********************************************************************************/
  20.176 +
  20.177 +NetlinkMessageError::NetlinkMessageError ()
  20.178 +  : m_error (0)
  20.179 +{
  20.180 +}
  20.181 +NetlinkMessageError::~NetlinkMessageError ()
  20.182 +{}
  20.183 +void 
  20.184 +NetlinkMessageError::SetError (int32_t v)
  20.185 +{
  20.186 +  m_error = v;
  20.187 +}
  20.188 +int32_t
  20.189 +NetlinkMessageError::GetError (void) const
  20.190 +{
  20.191 +  return m_error;
  20.192 +}
  20.193 +void
  20.194 +NetlinkMessageError::SetMsg (NetlinkMessageHeader v)
  20.195 +{
  20.196 +  m_msg = v;
  20.197 +}
  20.198 +NetlinkMessageHeader
  20.199 +NetlinkMessageError::GetMsg (void) const
  20.200 +{
  20.201 +  return m_msg;
  20.202 +}
  20.203 +
  20.204 +TypeId 
  20.205 +NetlinkMessageError::GetTypeId (void)
  20.206 +{
  20.207 +  static TypeId tid = TypeId ("ns3::NetlinkMessageError")
  20.208 +    .SetParent<NetlinkPayload> ()
  20.209 +    .AddConstructor<NetlinkMessageError> ()
  20.210 +    ;
  20.211 +  return tid;
  20.212 +}
  20.213 +
  20.214 +TypeId 
  20.215 +NetlinkMessageError::GetInstanceTypeId (void) const
  20.216 +{
  20.217 +  return GetTypeId ();
  20.218 +}
  20.219 +void 
  20.220 +NetlinkMessageError::Print (std::ostream &os) const
  20.221 +{  
  20.222 +  os << "----NetlinkMessageError "
  20.223 +     << "error: " << m_error << " "
  20.224 +     << "msg:( ";
  20.225 +  m_msg.Print(os);
  20.226 +  os << " )";
  20.227 +}
  20.228 +
  20.229 +uint32_t 
  20.230 +NetlinkMessageError::GetSerializedSize (void) const
  20.231 +{
  20.232 +  /* this is the size of an nlmsgerr payload. */
  20.233 +  return NETLINK_MSG_ERROR_SIZE;
  20.234 +}
  20.235 +
  20.236 +void
  20.237 +NetlinkMessageError::Serialize (Buffer::Iterator& start) const
  20.238 +{
  20.239 +  start.WriteU32 (m_error);
  20.240 +  m_msg.Serialize (start);
  20.241 +}
  20.242 +
  20.243 +uint32_t
  20.244 +NetlinkMessageError::Deserialize (Buffer::Iterator& start)
  20.245 +{  
  20.246 +  m_error = start.ReadU32 ();
  20.247 +  m_msg.Deserialize (start);
  20.248 +  
  20.249 +  return GetSerializedSize ();
  20.250 +}
  20.251 +
  20.252 +
  20.253 +
  20.254 +
  20.255 +/***********************************************************************************
  20.256 +* \ NetlinkMessage
  20.257 +***********************************************************************************/
  20.258 +NetlinkMessage::NetlinkMessage ()
  20.259 +{}
  20.260 +
  20.261 +void
  20.262 +NetlinkMessage::SetHeader (NetlinkMessageHeader hdr)
  20.263 +{
  20.264 +  m_hdr = hdr;
  20.265 +}
  20.266 +NetlinkMessageHeader
  20.267 +NetlinkMessage::GetHeader (void)const
  20.268 +{
  20.269 +  return m_hdr;
  20.270 +}
  20.271 +void
  20.272 +NetlinkMessage::SetGeneralMessage (GeneralMessage genmsg)
  20.273 +{
  20.274 +  m_genmsg = genmsg;
  20.275 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + genmsg.GetSerializedSize ());
  20.276 +}
  20.277 +void
  20.278 +NetlinkMessage::SetErrorMessage (NetlinkMessageError errmsg)
  20.279 +{
  20.280 +  m_errorMessage = errmsg;
  20.281 +  m_hdr.SetMsgLen(m_hdr.GetSerializedSize () + errmsg.GetSerializedSize ());
  20.282 +}
  20.283 +// the type is one of RTM_NEWLINK,RTM_DELLINK,RTM_GETLINK
  20.284 +void
  20.285 +NetlinkMessage::SetInterfaceInfoMessage (InterfaceInfoMessage v)
  20.286 +{
  20.287 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  20.288 +  m_interfaceTemplate = v;
  20.289 +}
  20.290 +// the type is one of RTM_NEWADDR,RTM_DELADDR,RTM_GETADDR
  20.291 +void NetlinkMessage::SetInterfaceAddressMessage (InterfaceAddressMessage v)
  20.292 +{
  20.293 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  20.294 +  m_addressTemplate = v;
  20.295 +}
  20.296 +// the type  is one of RTM_NEWROUTE,RTM_DELROUTE,RTM_GETROUTE
  20.297 +void NetlinkMessage::SetRouteMessage (RouteMessage v)
  20.298 +{
  20.299 +  m_hdr.SetMsgLen (m_hdr.GetSerializedSize () + v.GetSerializedSize ());
  20.300 +  m_routeTemplate = v;
  20.301 +}
  20.302 +GeneralMessage
  20.303 +NetlinkMessage::GetGeneralMessage (void) const
  20.304 +{
  20.305 +  return m_genmsg;
  20.306 +}
  20.307 +NetlinkMessageError
  20.308 +NetlinkMessage::GetErrorMessage (void) const
  20.309 +{
  20.310 +  return m_errorMessage;
  20.311 +}
  20.312 +InterfaceInfoMessage
  20.313 +NetlinkMessage::GetInterfaceInfoMessage (void) const
  20.314 +{
  20.315 +  return m_interfaceTemplate;
  20.316 +}
  20.317 +InterfaceAddressMessage
  20.318 +NetlinkMessage::GetInterfaceAddressMessage (void) const
  20.319 +{
  20.320 +  return m_addressTemplate;
  20.321 +}
  20.322 +RouteMessage
  20.323 +NetlinkMessage::GetRouteMessage (void) const
  20.324 +{
  20.325 +  return m_routeTemplate;
  20.326 +}
  20.327 +bool
  20.328 +NetlinkMessage::IsMessageNetlinkControl (uint16_t type)
  20.329 +{
  20.330 +  return (type < NETLINK_RTM_BASE);
  20.331 +}
  20.332 +bool
  20.333 +NetlinkMessage::IsMessageNetlinkRoute (uint16_t type)
  20.334 +{
  20.335 +  return (type >= NETLINK_RTM_BASE && type < NETLINK_RTM_MAX);
  20.336 +}
  20.337 +bool
  20.338 +NetlinkMessage::IsMessageAddress (uint16_t type)
  20.339 +{
  20.340 +  return (type >= NETLINK_RTM_NEWADDR && type <= NETLINK_RTM_GETADDR);
  20.341 +}
  20.342 +bool
  20.343 +NetlinkMessage::IsMessageInterface (uint16_t type)
  20.344 +{
  20.345 +  return (type >= NETLINK_RTM_NEWLINK && type <= NETLINK_RTM_SETLINK);
  20.346 +}
  20.347 +bool
  20.348 +NetlinkMessage::IsMessageRoute (uint16_t type)
  20.349 +{
  20.350 +  return (type >= NETLINK_RTM_NEWROUTE && type <= NETLINK_RTM_GETROUTE);
  20.351 +}
  20.352 +bool
  20.353 +NetlinkMessage::IsMessageTypeGet (uint16_t type)
  20.354 +{
  20.355 +  return ((( type - NETLINK_RTM_BASE)&3) == 2);
  20.356 +}
  20.357 +bool
  20.358 +NetlinkMessage::IsMessageFlagsAck (uint16_t flags)
  20.359 +{
  20.360 +  return (flags & NETLINK_MSG_F_ACK) ? true : false;
  20.361 +}
  20.362 +bool
  20.363 +NetlinkMessage::IsMessageFlagsRequest (uint16_t flags)
  20.364 +{
  20.365 +  return (flags & NETLINK_MSG_F_REQUEST) ? true : false;
  20.366 +}
  20.367 +bool
  20.368 +NetlinkMessage::IsMessageFlagsDump (uint16_t flags)
  20.369 +{
  20.370 +  return (flags & NETLINK_MSG_F_DUMP) ? true : false;
  20.371 +}
  20.372 +
  20.373 +NetlinkMessage::operator MultipartNetlinkMessage (void) const
  20.374 +{
  20.375 +  MultipartNetlinkMessage multi_nlmsg;
  20.376 +  multi_nlmsg.AppendMessage (*this);
  20.377 +  return multi_nlmsg;
  20.378 +}
  20.379 +
  20.380 +TypeId 
  20.381 +NetlinkMessage::GetTypeId (void)
  20.382 +{
  20.383 +  static TypeId tid = TypeId ("ns3::NetlinkMessage")
  20.384 +    .SetParent<Header> ()
  20.385 +    .AddConstructor<NetlinkMessage> ()
  20.386 +    ;
  20.387 +  return tid;
  20.388 +}
  20.389 +TypeId 
  20.390 +NetlinkMessage::GetInstanceTypeId (void) const
  20.391 +{
  20.392 +  return GetTypeId ();
  20.393 +}
  20.394 +
  20.395 +uint32_t
  20.396 +NetlinkMessage::GetTotalSize (void) const
  20.397 +{
  20.398 +  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
  20.399 +}
  20.400 +
  20.401 +uint32_t
  20.402 +NetlinkMessage::GetMsgSize (void) const
  20.403 +{
  20.404 +  return m_hdr.GetMsgLen ();
  20.405 +}
  20.406 +
  20.407 +uint32_t
  20.408 +NetlinkMessage::GetPayloadSize (void) const
  20.409 +{
  20.410 +  return m_hdr.GetPayloadSize ();
  20.411 +}
  20.412 +uint16_t
  20.413 +NetlinkMessage::GetMsgType (void) const
  20.414 +{
  20.415 +  return m_hdr.GetMsgType ();
  20.416 +}
  20.417 +
  20.418 +uint8_t
  20.419 +NetlinkMessage::GetFamily(void) const
  20.420 +{
  20.421 +  if (IsMessageTypeGet (GetMsgType ()))
  20.422 +    {
  20.423 +      NS_LOG_DEBUG ("TypeGetMsg");
  20.424 +    }
  20.425 +  if (IsMessageAddress (m_hdr.GetMsgType ()))
  20.426 +    {
  20.427 +      return m_addressTemplate.GetFamily ();
  20.428 +    }
  20.429 +  else if (IsMessageInterface(m_hdr.GetMsgType ()))
  20.430 +    {
  20.431 +      return m_interfaceTemplate.GetFamily ();
  20.432 +    }
  20.433 +  else if (IsMessageRoute(m_hdr.GetMsgType ()))
  20.434 +    {
  20.435 +      return m_routeTemplate.GetFamily ();
  20.436 +    }
  20.437 +  else if (IsMessageFlagsDump (m_hdr.GetMsgFlags ()))
  20.438 +    {
  20.439 +      return m_genmsg.GetFamily (); //value is said to be always set to AF_UNSPEC
  20.440 +    }
  20.441 +  else
  20.442 +    {
  20.443 +      NS_LOG_WARN ("Netlink message type not supported, return AF_UNSPEC");
  20.444 +      return 0;
  20.445 +    }
  20.446 +}
  20.447 +
  20.448 +void 
  20.449 +NetlinkMessage::Print (std::ostream &os) const
  20.450 +{
  20.451 +  uint16_t type = m_hdr.GetMsgType ();
  20.452 +
  20.453 +  os << "NetlinkMessage  ";
  20.454 +  os << " ----Header:(";
  20.455 +  m_hdr.Print(os);
  20.456 +  os << ")";
  20.457 +
  20.458 +  if (type == NETLINK_MSG_DONE )
  20.459 +    {
  20.460 +      os << "multipart message ends here";
  20.461 +    }
  20.462 +  else if (type == NETLINK_MSG_ERROR )
  20.463 +    {
  20.464 +      m_errorMessage.Print (os);
  20.465 +    }
  20.466 +  else if (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK)
  20.467 +    {
  20.468 +      m_genmsg.Print (os);
  20.469 +    }  
  20.470 +  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE)
  20.471 +    {
  20.472 +      m_routeTemplate.Print (os);
  20.473 +    }
  20.474 +  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  20.475 +    {
  20.476 +      m_addressTemplate.Print (os);
  20.477 +    }
  20.478 +  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_DELLINK)
  20.479 +    {
  20.480 +      m_interfaceTemplate.Print (os);
  20.481 +    }
  20.482 +  else
  20.483 +    {
  20.484 +      os << "service not supported yet( " << type <<")";
  20.485 +    }
  20.486 +}
  20.487 +uint32_t 
  20.488 +NetlinkMessage::GetSerializedSize (void) const
  20.489 +{
  20.490 +  return NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ());
  20.491 +}
  20.492 +
  20.493 +void
  20.494 +NetlinkMessage::Serialize (Buffer::Iterator& start) const
  20.495 +{
  20.496 +  NS_LOG_FUNCTION (this);
  20.497 +  //  Print (std::cout);
  20.498 +  uint16_t type = m_hdr.GetMsgType ();
  20.499 +
  20.500 +  m_hdr.Serialize (start);
  20.501 +
  20.502 +  if (type == NETLINK_MSG_DONE)
  20.503 +    {
  20.504 +      //nothing done
  20.505 +    }
  20.506 +  else if (type == NETLINK_MSG_ERROR)
  20.507 +    {
  20.508 +      m_errorMessage.Serialize (start);
  20.509 +    }  
  20.510 +  else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags ()) && 
  20.511 +           (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
  20.512 +    {
  20.513 +      m_genmsg.Serialize (start);
  20.514 +    }  
  20.515 +  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  20.516 +    {
  20.517 +      m_routeTemplate.Serialize (start);
  20.518 +    }
  20.519 +  else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  20.520 +    {
  20.521 +      m_addressTemplate.Serialize (start);
  20.522 +    }
  20.523 +  else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
  20.524 +    {
  20.525 +      m_interfaceTemplate.Serialize (start);
  20.526 +    }
  20.527 +  else
  20.528 +    {
  20.529 +    }  
  20.530 +}
  20.531 +
  20.532 +
  20.533 +uint32_t
  20.534 +NetlinkMessage::Deserialize (Buffer::Iterator&start)
  20.535 +{
  20.536 +  uint32_t remaining;
  20.537 +
  20.538 +  m_hdr.Deserialize (start);
  20.539 +  remaining = NETLINK_MSG_ALIGN (m_hdr.GetMsgLen ()) - m_hdr.GetSerializedSize ();
  20.540 +  
  20.541 +  //Deserialize service module
  20.542 +  uint16_t type = GetMsgType ();
  20.543 +  if (remaining)
  20.544 +    {        
  20.545 +      if (type == NETLINK_MSG_DONE)
  20.546 +        {
  20.547 +          //do nothing
  20.548 +        }
  20.549 +      else if (type == NETLINK_MSG_ERROR)
  20.550 +        {
  20.551 +          remaining -= m_errorMessage.Deserialize (start);
  20.552 +        }      
  20.553 +      else if (NetlinkMessage::IsMessageFlagsDump (m_hdr.GetMsgFlags()) &&
  20.554 +               (type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETLINK))
  20.555 +        {
  20.556 +          remaining -= m_genmsg.Deserialize (start, remaining);
  20.557 +        }
  20.558 +      else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  20.559 +        {
  20.560 +          remaining -= m_routeTemplate.Deserialize (start, remaining);
  20.561 +        }
  20.562 +      else if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  20.563 +        {
  20.564 +          remaining -= m_addressTemplate.Deserialize (start, remaining);
  20.565 +        }
  20.566 +      else if (type == NETLINK_RTM_NEWLINK || type == NETLINK_RTM_SETLINK)
  20.567 +        {
  20.568 +          remaining -= m_interfaceTemplate.Deserialize (start, remaining);
  20.569 +        }
  20.570 +      else
  20.571 +        {
  20.572 +          //do nothing
  20.573 +        }
  20.574 +    }
  20.575 +
  20.576 +  return GetSerializedSize ();
  20.577 +}
  20.578 +
  20.579 +
  20.580 +/***********************************************************************************
  20.581 +* \ MultipartNetlinkMessage
  20.582 +***********************************************************************************/
  20.583 +MultipartNetlinkMessage::MultipartNetlinkMessage ()
  20.584 +{}
  20.585 +
  20.586 +TypeId 
  20.587 +MultipartNetlinkMessage::GetTypeId (void)
  20.588 +{
  20.589 +  static TypeId tid = TypeId ("ns3::MultipartNetlinkMessage")
  20.590 +    .SetParent<Header> ()
  20.591 +    .AddConstructor<MultipartNetlinkMessage> ()
  20.592 +    ;
  20.593 +  return tid;
  20.594 +}
  20.595 +TypeId 
  20.596 +MultipartNetlinkMessage::GetInstanceTypeId (void) const
  20.597 +{
  20.598 +  return GetTypeId ();
  20.599 +}
  20.600 +
  20.601 +void
  20.602 +MultipartNetlinkMessage::Print (std::ostream &os) const
  20.603 +{
  20.604 +  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  20.605 +    {
  20.606 +      m_netlinkMessages[i].Print (os);
  20.607 +    }
  20.608 +}
  20.609 +uint32_t
  20.610 +MultipartNetlinkMessage::GetSerializedSize (void) const
  20.611 +{
  20.612 +  uint32_t len = 0;
  20.613 +
  20.614 +  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  20.615 +    {
  20.616 +      len +=  m_netlinkMessages[i].GetSerializedSize ();
  20.617 +    }
  20.618 +  return len;
  20.619 +}
  20.620 +void
  20.621 +MultipartNetlinkMessage::Serialize (Buffer::Iterator start) const
  20.622 +{
  20.623 +  NS_LOG_FUNCTION ("Multi" << this);
  20.624 +  for (uint32_t i = 0; i <  m_netlinkMessages.size (); i ++)
  20.625 +    {
  20.626 +      m_netlinkMessages[i].Serialize (start);
  20.627 +    }
  20.628 +}
  20.629 +uint32_t
  20.630 +MultipartNetlinkMessage::Deserialize (Buffer::Iterator start)
  20.631 +{
  20.632 +  while (1)
  20.633 +    {
  20.634 +      NetlinkMessage nlmsg;
  20.635 +      nlmsg.Deserialize (start);
  20.636 +      AppendMessage (nlmsg);
  20.637 +
  20.638 +      if (!(nlmsg.GetHeader ().GetMsgFlags () & NETLINK_MSG_F_MULTI))
  20.639 +        {
  20.640 +          break;
  20.641 +        }
  20.642 +
  20.643 +      if (nlmsg.GetHeader ().GetMsgType() == NETLINK_MSG_DONE)
  20.644 +        {
  20.645 +          break;
  20.646 +        }
  20.647 +    }
  20.648 +  return GetSerializedSize ();
  20.649 +}
  20.650 +
  20.651 +void
  20.652 +MultipartNetlinkMessage::AppendMessage (NetlinkMessage nlmsg)
  20.653 +{
  20.654 +  m_netlinkMessages.push_back (nlmsg);
  20.655 +}
  20.656 +
  20.657 +void
  20.658 +MultipartNetlinkMessage::Clear ()
  20.659 +{
  20.660 +  m_netlinkMessages.clear ();
  20.661 +}
  20.662 +
  20.663 +uint32_t
  20.664 +MultipartNetlinkMessage::GetNMessages (void) const
  20.665 +{
  20.666 +  return m_netlinkMessages.size ();
  20.667 +}
  20.668 +NetlinkMessage
  20.669 +MultipartNetlinkMessage::GetMessage (uint32_t index) const
  20.670 +{
  20.671 +  NS_ASSERT(index < m_netlinkMessages.size ());
  20.672 +  return m_netlinkMessages[index];
  20.673 +}
  20.674 +
  20.675 +}; // namespace ns3
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/netlink/netlink-message.h	Thu May 05 09:28:21 2011 +0200
    21.3 @@ -0,0 +1,256 @@
    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_MESSAGE_H
   21.26 +#define NETLINK_MESSAGE_H
   21.27 +
   21.28 +#include "ns3/header.h"
   21.29 +#include "ns3/address.h"
   21.30 +#include "netlink-message-route.h"
   21.31 +#include "netlink-attribute.h"
   21.32 +
   21.33 +
   21.34 +namespace ns3 {
   21.35 +  class NetlinkPayload;
   21.36 +  class GeneralMessage;
   21.37 +  class InterfaceAddressMessage;
   21.38 +  class InterfaceInfoMessage;
   21.39 +  class RouteMessage;
   21.40 +  class MultipartNetlinkMessage;
   21.41 +
   21.42 +/**
   21.43 +* \brief The Netlink message structure for an netlink packet
   21.44 +* 
   21.45 +There are three levels to a Netlink message: The general Netlink
   21.46 +message header, the IP service specific template, and the IP service
   21.47 +specific data.
   21.48 +
   21.49 +0                   1                   2                   3
   21.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
   21.51 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   21.52 +|                                                               |
   21.53 +|                   Netlink message header                      |
   21.54 +|                                                               |
   21.55 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   21.56 +|                                                               |
   21.57 +|                  IP Service Template                          |
   21.58 +|                                                               |
   21.59 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   21.60 +|                                                               |
   21.61 +|                  IP Service specific data in TLVs             |
   21.62 +|                                                               |
   21.63 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   21.64 +*/
   21.65 +
   21.66 +  enum NetlinkMessageFlag
   21.67 +  {
   21.68 +    NETLINK_MSG_F_REQUEST = 1,  // It is request message.
   21.69 +    NETLINK_MSG_F_MULTI = 2,    // Multipart message, terminated by NETLINK_MSG_DONE
   21.70 +    NETLINK_MSG_F_ACK = 4,      // Reply with ack, with zero or error code
   21.71 +    NETLINK_MSG_F_ECHO = 8,     // Echo this request 
   21.72 +
   21.73 +    /* Modifiers to Get request */
   21.74 +    NETLINK_MSG_F_ROOT = 0x100,        // specify tree root
   21.75 +    NETLINK_MSG_F_MATCH = 0x200,       // return all matching
   21.76 +    NETLINK_MSG_F_ATOMIC = 0x400,      // atomic Get =
   21.77 +    NETLINK_MSG_F_DUMP = (NETLINK_MSG_F_ROOT|NETLINK_MSG_F_MATCH),
   21.78 +
   21.79 +    /* Modifiers to NEW request */
   21.80 +    NETLINK_MSG_F_REPLACE = 0x100, // Override existing = 
   21.81 +    NETLINK_MSG_F_EXCL = 0x200,   // Do not touch, if it exists
   21.82 +    NETLINK_MSG_F_CREATE = 0x400,  // Create, if it does not exist
   21.83 +    NETLINK_MSG_F_APPEND = 0x800,  // Add to end of list = 
   21.84 +  };
   21.85 +
   21.86 +  enum NetlinkMessageType
   21.87 +  {
   21.88 +    NETLINK_MSG_NOOP = 0x1,          // Nothing.
   21.89 +    NETLINK_MSG_ERROR = 0x2,         // Error
   21.90 +    NETLINK_MSG_DONE = 0x3,          // End of a dump
   21.91 +    NETLINK_MSG_OVERRUN = 0x4,       // Data lost
   21.92 +    NETLINK_MSG_MIN_TYPE = 0x10,     // < 0x10: reserved control messages
   21.93 +  };
   21.94 +
   21.95 +#define NETLINK_MSG_ALIGNTO 4
   21.96 +#define NETLINK_MSG_ALIGN(X)    (((X)+NETLINK_MSG_ALIGNTO-1) & ~(NETLINK_MSG_ALIGNTO-1) )
   21.97 +
   21.98 +class NetlinkMessageHeader : public ObjectBase
   21.99 +{
  21.100 +public:
  21.101 +  NetlinkMessageHeader ();
  21.102 +  NetlinkMessageHeader (uint16_t type, uint16_t flags, uint32_t seq, uint32_t pid);
  21.103 +
  21.104 +  static TypeId GetTypeId (void);
  21.105 +  virtual TypeId GetInstanceTypeId (void) const;
  21.106 +  void Print (std::ostream &os) const;
  21.107 +  uint32_t GetSerializedSize (void) const;
  21.108 +  void Serialize (Buffer::Iterator& start) const;
  21.109 +  uint32_t Deserialize (Buffer::Iterator& start);
  21.110 +
  21.111 +  void SetMsgLen (uint32_t v);
  21.112 +  void SetMsgFlags (uint16_t v);
  21.113 +  void SetMsgType (uint16_t v);
  21.114 +  void SetMsgSeq (uint32_t v);
  21.115 +  void SetMsgPid (uint32_t v);
  21.116 +  uint32_t GetMsgLen (void) const;
  21.117 +  uint16_t GetMsgFlags (void) const;
  21.118 +  uint16_t GetMsgType (void) const;
  21.119 +  uint32_t GetMsgSeq (void) const;
  21.120 +  uint32_t GetMsgPid (void) const;
  21.121 +
  21.122 +  static uint32_t GetHeaderSize ();
  21.123 +  uint32_t GetPayloadSize (void) const;
  21.124 +
  21.125 +private:
  21.126 +  static const uint32_t NETLINK_MSG_HEADER_SIZE = 16; /* size of the nlmsghdr field*/
  21.127 +  uint32_t m_nlmsgLen;	/* Length of message including header */
  21.128 +  uint16_t m_nlmsgType;	/* Message content */
  21.129 +  uint16_t m_nlmsgFlags;	/* Additional flags */
  21.130 +  uint32_t m_nlmsgSeq;	/* Sequence number */
  21.131 +  uint32_t m_nlmsgPid;	/* Sending process PID */
  21.132 +};
  21.133 +
  21.134 +/**
  21.135 +* \brief The struct nlmsgerr
  21.136 +*/
  21.137 +class NetlinkMessageError : public NetlinkPayload
  21.138 +{
  21.139 +public:
  21.140 +  NetlinkMessageError ();
  21.141 +  virtual ~NetlinkMessageError();
  21.142 +
  21.143 +  static TypeId GetTypeId (void);
  21.144 +  virtual TypeId GetInstanceTypeId (void) const;
  21.145 +  virtual void Serialize (Buffer::Iterator& start) const;
  21.146 +  virtual uint32_t Deserialize (Buffer::Iterator& start);
  21.147 +  virtual void Print (std::ostream &os) const;
  21.148 +  virtual uint32_t GetSerializedSize (void) const;
  21.149 +
  21.150 +  void SetError (int32_t v);
  21.151 +  int32_t GetError (void) const;
  21.152 +  void SetMsg(NetlinkMessageHeader v);
  21.153 +  NetlinkMessageHeader GetMsg (void) const;
  21.154 +
  21.155 +private:
  21.156 +  static const int NETLINK_MSG_ERROR_SIZE = 20; /* size of the nlmsgerror field*/
  21.157 +  int32_t m_error;
  21.158 +  NetlinkMessageHeader m_msg;        
  21.159 +};
  21.160 +
  21.161 +
  21.162 +class NetlinkMessage : public ObjectBase
  21.163 +{
  21.164 +public:
  21.165 +  NetlinkMessage ();
  21.166 +
  21.167 +  static TypeId GetTypeId (void);
  21.168 +  TypeId GetInstanceTypeId (void) const;
  21.169 +  void Print (std::ostream &os) const;
  21.170 +  uint32_t GetSerializedSize (void) const;
  21.171 +  void Serialize (Buffer::Iterator& start) const;
  21.172 +  uint32_t Deserialize (Buffer::Iterator& start);
  21.173 +
  21.174 +  operator MultipartNetlinkMessage (void) const;
  21.175 +
  21.176 +  uint32_t GetTotalSize (void) const;  //length of netlink message including padding
  21.177 +  uint32_t GetMsgSize (void) const;    //length of netlink message not including padding
  21.178 +  uint32_t GetPayloadSize (void) const; //length of message payload
  21.179 +  uint16_t GetMsgType (void) const;
  21.180 +  uint8_t GetFamily(void) const;
  21.181 +
  21.182 +  void SetHeader (NetlinkMessageHeader hdr);
  21.183 +  NetlinkMessageHeader GetHeader (void) const;
  21.184 +
  21.185 +  //before set message body, should set header first
  21.186 +  void SetErrorMessage (NetlinkMessageError errmsg);
  21.187 +  void SetGeneralMessage (GeneralMessage genmsg);
  21.188 +  void SetInterfaceInfoMessage (InterfaceInfoMessage v);
  21.189 +  void SetInterfaceAddressMessage (InterfaceAddressMessage v);
  21.190 +  void SetRouteMessage (RouteMessage v);
  21.191 +  NetlinkMessageError GetErrorMessage (void) const;
  21.192 +  GeneralMessage GetGeneralMessage (void) const;
  21.193 +  InterfaceInfoMessage GetInterfaceInfoMessage (void) const;
  21.194 +  InterfaceAddressMessage GetInterfaceAddressMessage (void) const;
  21.195 +  RouteMessage GetRouteMessage (void) const;
  21.196 +
  21.197 +  /**
  21.198 +  * \returns true if type was control type, false otherwise.
  21.199 +  */
  21.200 +  static bool IsMessageNetlinkControl (uint16_t type);
  21.201 +  /**
  21.202 +  * \returns true if type was netlink route, false otherwise.
  21.203 +  */
  21.204 +  static bool IsMessageNetlinkRoute (uint16_t type);
  21.205 +  static bool IsMessageAddress (uint16_t type);
  21.206 +  static bool IsMessageInterface (uint16_t type);
  21.207 +  static bool IsMessageRoute (uint16_t type);
  21.208 +  /**
  21.209 +  * \returns true if type was GETxxx , false otherwise.
  21.210 +  */
  21.211 +  static bool IsMessageTypeGet (uint16_t type);
  21.212 +  /**
  21.213 +  * \returns true if flag has ack , false otherwise.
  21.214 +  */
  21.215 +  static bool IsMessageFlagsAck (uint16_t flags);
  21.216 +  /**
  21.217 +  * \returns true if flag has request , false otherwise.
  21.218 +  */
  21.219 +  static bool IsMessageFlagsRequest (uint16_t flags);
  21.220 +  /**
  21.221 +  * \returns true if flag has dump , false otherwise.
  21.222 +  */
  21.223 +  static bool IsMessageFlagsDump (uint16_t flags);
  21.224 +
  21.225 +private:
  21.226 +  NetlinkMessageHeader m_hdr;
  21.227 +
  21.228 +  //only one type of messages below exists in real world application
  21.229 +  NetlinkMessageError m_errorMessage;  
  21.230 +  GeneralMessage m_genmsg;
  21.231 +  InterfaceInfoMessage m_interfaceTemplate;
  21.232 +  InterfaceAddressMessage m_addressTemplate;
  21.233 +  RouteMessage m_routeTemplate;
  21.234 +};
  21.235 +
  21.236 +class MultipartNetlinkMessage : public Header
  21.237 +{
  21.238 +public:
  21.239 +  MultipartNetlinkMessage ();
  21.240 +
  21.241 +  static TypeId GetTypeId (void);
  21.242 +  virtual TypeId GetInstanceTypeId (void) const;
  21.243 +  virtual void Print (std::ostream &os) const;
  21.244 +  virtual uint32_t GetSerializedSize (void) const;
  21.245 +  virtual void Serialize (Buffer::Iterator start) const;
  21.246 +  virtual uint32_t Deserialize (Buffer::Iterator start);
  21.247 +
  21.248 +  void AppendMessage (NetlinkMessage nlmsg);
  21.249 +  void Clear();
  21.250 +  uint32_t GetNMessages (void) const;
  21.251 +  NetlinkMessage GetMessage (uint32_t index) const;
  21.252 +
  21.253 +private:
  21.254 +  std::vector<NetlinkMessage> m_netlinkMessages;
  21.255 +};
  21.256 +
  21.257 +}; // namespace ns3
  21.258 +
  21.259 +#endif /* NETLINK_MESSAGE_H */
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/netlink/netlink-socket-address.cc	Thu May 05 09:28:21 2011 +0200
    22.3 @@ -0,0 +1,121 @@
    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-address.h"
   22.26 +
   22.27 +namespace ns3 {
   22.28 +
   22.29 +NetlinkSocketAddress::NetlinkSocketAddress (uint32_t pid, uint32_t groups)
   22.30 +  : m_pid(pid),
   22.31 +    m_groups(groups)
   22.32 +{}
   22.33 +
   22.34 +NetlinkSocketAddress::NetlinkSocketAddress ()
   22.35 +  : m_pid (0),
   22.36 +    m_groups (0)
   22.37 +{}
   22.38 +
   22.39 +NetlinkSocketAddress::~NetlinkSocketAddress ()
   22.40 +{}
   22.41 +
   22.42 +void NetlinkSocketAddress::SetProcessID (uint32_t pid)
   22.43 +{
   22.44 +  m_pid = pid;
   22.45 +}
   22.46 +
   22.47 +void NetlinkSocketAddress::SetGroupsMask (uint32_t mask)
   22.48 +{
   22.49 +  m_groups = mask;
   22.50 +}
   22.51 +
   22.52 +uint32_t NetlinkSocketAddress::GetProcessID (void) const
   22.53 +{
   22.54 +  return m_pid;
   22.55 +}
   22.56 +
   22.57 +uint32_t NetlinkSocketAddress::GetGroupsMask (void) const
   22.58 +{
   22.59 +  return m_groups;
   22.60 +}
   22.61 +
   22.62 +NetlinkSocketAddress::operator Address (void) const
   22.63 +{
   22.64 +  return ConvertTo ();
   22.65 +}
   22.66 +
   22.67 +Address NetlinkSocketAddress::ConvertTo (void) const
   22.68 +{
   22.69 +  uint8_t buffer[8];
   22.70 +
   22.71 +  buffer[0] = (m_pid >> 24) & 0xff;
   22.72 +  buffer[1] = (m_pid >> 16) & 0xff;
   22.73 +  buffer[2] = (m_pid >> 8) & 0xff;
   22.74 +  buffer[3] = (m_pid >> 0) & 0xff;
   22.75 +  buffer[4] = (m_groups >> 24) & 0xff;
   22.76 +  buffer[5] = (m_groups >> 16) & 0xff;
   22.77 +  buffer[6] = (m_groups >> 8) & 0xff;
   22.78 +  buffer[7] = (m_groups >> 0) & 0xff;
   22.79 +
   22.80 +  return Address (GetType (), buffer, 8);
   22.81 +}
   22.82 +
   22.83 +NetlinkSocketAddress NetlinkSocketAddress::ConvertFrom (const Address &address)
   22.84 +{
   22.85 +  NS_ASSERT (IsMatchingType (address));
   22.86 +
   22.87 +  NetlinkSocketAddress nl;
   22.88 +  uint8_t buf[8];
   22.89 +
   22.90 +  address.CopyTo (buf);
   22.91 +
   22.92 +  nl.m_pid = 0;
   22.93 +  nl.m_pid |= buf[0];
   22.94 +  nl.m_pid <<= 8;
   22.95 +  nl.m_pid |= buf[1];
   22.96 +  nl.m_pid <<= 8;
   22.97 +  nl.m_pid |= buf[2];
   22.98 +  nl.m_pid <<= 8;
   22.99 +  nl.m_pid |= buf[3];
  22.100 +
  22.101 +  nl.m_groups = 0;
  22.102 +  nl.m_groups |= buf[4];
  22.103 +  nl.m_groups <<= 8;
  22.104 +  nl.m_groups |= buf[5];
  22.105 +  nl.m_groups <<= 8;
  22.106 +  nl.m_groups |= buf[6];
  22.107 +  nl.m_groups <<= 8;
  22.108 +  nl.m_groups |= buf[7];
  22.109 +
  22.110 +  return nl;
  22.111 +}
  22.112 +
  22.113 +bool NetlinkSocketAddress::IsMatchingType (const Address &address)
  22.114 +{
  22.115 +  return address.IsMatchingType (GetType ());
  22.116 +}
  22.117 +
  22.118 +uint8_t NetlinkSocketAddress::GetType (void)
  22.119 +{
  22.120 +  static uint8_t type = Address::Register ();
  22.121 +  return type;
  22.122 +}
  22.123 +
  22.124 +} // namespace ns3
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/netlink/netlink-socket-address.h	Thu May 05 09:28:21 2011 +0200
    23.3 @@ -0,0 +1,71 @@
    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_ADDRESS_H
   23.26 +#define NETLINK_SOCKET_ADDRESS_H
   23.27 +
   23.28 +#include "ns3/ptr.h"
   23.29 +#include "ns3/address.h"
   23.30 +
   23.31 +namespace ns3 {
   23.32 +
   23.33 +class NetlinkSocketAddress
   23.34 +{
   23.35 +public:
   23.36 +  NetlinkSocketAddress (uint32_t pid, uint32_t groups);
   23.37 +  NetlinkSocketAddress ();
   23.38 +  ~NetlinkSocketAddress ();
   23.39 +
   23.40 +  void SetProcessID (uint32_t pid);
   23.41 +  void SetGroupsMask (uint32_t mask);
   23.42 +
   23.43 +  uint32_t GetProcessID (void) const;
   23.44 +  uint32_t GetGroupsMask (void) const;
   23.45 +
   23.46 +  /**
   23.47 +  * \returns an Address instance which represents this
   23.48 +  * NetlinkSocketAddress instance.
   23.49 +  */
   23.50 +  operator Address (void) const;
   23.51 +  /**
   23.52 +  * \param address the Address instance to convert from.
   23.53 +  *
   23.54 +  * Returns an NetlinkSocketAddress which corresponds to the input
   23.55 +  * Address
   23.56 +  */
   23.57 +  static NetlinkSocketAddress ConvertFrom (const Address &address);
   23.58 +  /**
   23.59 +  * \returns true if the address matches, false otherwise.
   23.60 +  */
   23.61 +  static bool IsMatchingType (const Address &address);
   23.62 +private:
   23.63 +  static uint8_t GetType (void);
   23.64 +  Address ConvertTo (void) const;
   23.65 +
   23.66 +  uint32_t m_pid;
   23.67 +  uint32_t m_groups;
   23.68 +
   23.69 +};
   23.70 +
   23.71 +
   23.72 +} // namespace ns3
   23.73 +
   23.74 +#endif /* NETLINK_SOCKET_ADDRESS_H */
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/netlink/netlink-socket-factory.cc	Thu May 05 09:28:21 2011 +0200
    24.3 @@ -0,0 +1,50 @@
    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-factory.h"
   24.26 +#include "netlink-socket.h"
   24.27 +#include "ns3/node.h"
   24.28 +
   24.29 +namespace ns3 {
   24.30 +
   24.31 +NS_OBJECT_ENSURE_REGISTERED (NetlinkSocketFactory);
   24.32 +
   24.33 +TypeId 
   24.34 +NetlinkSocketFactory::GetTypeId (void)
   24.35 +{
   24.36 +  static TypeId tid = TypeId ("ns3::NetlinkSocketFactory")
   24.37 +    .AddConstructor<NetlinkSocketFactory> ()
   24.38 +    .SetParent<SocketFactory> ()
   24.39 +    ;
   24.40 +  return tid;
   24.41 +}
   24.42 +
   24.43 +NetlinkSocketFactory::NetlinkSocketFactory ()
   24.44 +{}
   24.45 +
   24.46 +Ptr<Socket> NetlinkSocketFactory::CreateSocket (void)
   24.47 +{
   24.48 +  Ptr<Node> node = GetObject<Node> ();
   24.49 +  Ptr<NetlinkSocket> socket = CreateObject<NetlinkSocket> ();
   24.50 +  socket->SetNode (node);
   24.51 +  return socket;
   24.52 +} 
   24.53 +} // namespace ns3
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/netlink/netlink-socket-factory.h	Thu May 05 09:28:21 2011 +0200
    25.3 @@ -0,0 +1,52 @@
    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 +
   25.25 +#ifndef NETLINK_SOCKET_FACTORY_H
   25.26 +#define NETLINK_SOCKET_FACTORY_H
   25.27 +
   25.28 +#include "ns3/socket-factory.h"
   25.29 +
   25.30 +namespace ns3 {
   25.31 +
   25.32 +class Socket;
   25.33 +
   25.34 +/**
   25.35 + * This can be used as an interface in a node in order for the node to
   25.36 + * generate NetlinkSockets.
   25.37 + */
   25.38 +class NetlinkSocketFactory : public SocketFactory
   25.39 +{
   25.40 +public:
   25.41 +  static TypeId GetTypeId (void);
   25.42 +
   25.43 +  NetlinkSocketFactory ();
   25.44 +
   25.45 +  /**
   25.46 +   * Creates a NetlinkSocket and returns a pointer to it.
   25.47 +   *
   25.48 +   * \return a pointer to the created socket
   25.49 +   */
   25.50 +  virtual Ptr<Socket> CreateSocket (void);
   25.51 +};
   25.52 +
   25.53 +} // namespace ns3
   25.54 +
   25.55 +#endif /* NETLINK_SOCKET_FACTORY_H */
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/netlink/netlink-socket.cc	Thu May 05 09:28:21 2011 +0200
    26.3 @@ -0,0 +1,1571 @@
    26.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    26.5 +/*
    26.6 + * Copyright (c) 2008 Liu Jian
    26.7 + *
    26.8 + * This program is free software; you can redistribute it and/or modify
    26.9 + * it under the terms of the GNU General Public License version 2 as
   26.10 + * published by the Free Software Foundation;
   26.11 + *
   26.12 + * This program is distributed in the hope that it will be useful,
   26.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   26.15 + * GNU General Public License for more details.
   26.16 + *
   26.17 + * You should have received a copy of the GNU General Public License
   26.18 + * along with this program; if not, write to the Free Software
   26.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26.20 + *
   26.21 + * Author: Liu Jian <liujatp@gmail.com>
   26.22 + *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   26.23 + */
   26.24 +
   26.25 +#include "netlink-socket.h"
   26.26 +#include "netlink-socket-address.h"
   26.27 +#include "netlink-message.h"
   26.28 +#include "netlink-message-route.h"
   26.29 +#include "ns3/log.h"
   26.30 +#include "ns3/node.h"
   26.31 +#include "ns3/packet.h"
   26.32 +#include "ns3/ipv4-address.h"
   26.33 +#include "ns3/ipv4.h"
   26.34 +#include "ns3/simple-net-device.h"
   26.35 +#include "ns3/uinteger.h"
   26.36 +#include "ns3/trace-source-accessor.h"
   26.37 +#include <iostream>
   26.38 +#include <sstream>
   26.39 +#include "ns3/ipv6-address.h"
   26.40 +#include "ns3/ipv6.h"
   26.41 +#include "ns3/ipv4-l3-protocol.h"
   26.42 +#include "ns3/ipv4-static-routing-helper.h"
   26.43 +#include "ns3/ipv4-routing-table-entry.h"
   26.44 +#include "ns3/ipv6-l3-protocol.h"
   26.45 +#include "ns3/ipv6-interface.h"
   26.46 +#include "ns3/ipv6-static-routing-helper.h"
   26.47 +#include "ns3/ipv6-routing-table-entry.h"
   26.48 +#include "ns3/socket.h"
   26.49 +#include "ns3/mac48-address.h"
   26.50 +#include <sys/socket.h>
   26.51 +#include <linux/if.h>
   26.52 +#include <errno.h>
   26.53 +
   26.54 +NS_LOG_COMPONENT_DEFINE ("NetlinkSocket");
   26.55 +
   26.56 +namespace ns3 {
   26.57 +
   26.58 +// GroupSockets store the netlinksocket with noero group value
   26.59 +// it was due to the mulitcast netlink messages.
   26.60 +class GroupSockets
   26.61 +{
   26.62 +public:
   26.63 +  static uint32_t GetNSockets(void)
   26.64 +  { 
   26.65 +    return m_Sockets.size();
   26.66 +  }
   26.67 +  static Ptr<NetlinkSocket> GetSocket(uint32_t index)
   26.68 +  {
   26.69 +    NS_ASSERT(index < m_Sockets.size());
   26.70 +    return m_Sockets[index];
   26.71 +  }
   26.72 +  static void AddSocket(Ptr<NetlinkSocket>sock)
   26.73 +  {
   26.74 +    m_Sockets.push_back(sock);
   26.75 +  }
   26.76 +private:
   26.77 +   /*use a std::vector to store the sockets with nozero group value*/
   26.78 +  static std::vector<Ptr<NetlinkSocket> >m_Sockets;
   26.79 +};
   26.80 +std::vector<Ptr<NetlinkSocket> >GroupSockets::m_Sockets;
   26.81 +
   26.82 +NS_OBJECT_ENSURE_REGISTERED (NetlinkSocket);
   26.83 +
   26.84 +/*
   26.85 +Netlink Socket
   26.86 +*/
   26.87 +TypeId
   26.88 +NetlinkSocket::GetTypeId (void)
   26.89 +{
   26.90 +  static TypeId tid = TypeId ("ns3::NetlinkSocket")
   26.91 +    .SetParent<Socket> ()
   26.92 +    .AddConstructor<NetlinkSocket> ()
   26.93 +    .AddTraceSource ("Drop", "Drop packet due to receive buffer overflow",
   26.94 +                     MakeTraceSourceAccessor (&NetlinkSocket::m_dropTrace))
   26.95 +    .AddAttribute ("RcvBufSize",
   26.96 +                   "NetlinkSocket maximum receive buffer size (bytes)",
   26.97 +                   UintegerValue (0xffffffffl),
   26.98 +                   MakeUintegerAccessor (&NetlinkSocket::m_rcvBufSize),
   26.99 +                   MakeUintegerChecker<uint32_t> ())
  26.100 +    .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is received on this socket.",
  26.101 +                   CallbackValue (),
  26.102 +                   MakeCallbackAccessor (&NetlinkSocket::m_icmpCallback),
  26.103 +                   MakeCallbackChecker ())
  26.104 +    ;
  26.105 +  return tid;
  26.106 +}
  26.107 +
  26.108 +NetlinkSocket::NetlinkSocket ()
  26.109 +  : m_shutdownSend (false),
  26.110 +    m_shutdownRecv (false),
  26.111 +    m_rxAvailable (0),
  26.112 +    m_srcPid (0),
  26.113 +    m_srcGroups (0),
  26.114 +    m_dstPid (0),
  26.115 +    m_dstGroups (0)
  26.116 +{
  26.117 +  NS_LOG_FUNCTION_NOARGS ();
  26.118 +  m_errno = ERROR_NOTERROR;
  26.119 +}
  26.120 +NetlinkSocket::~NetlinkSocket ()
  26.121 +{
  26.122 +  NS_LOG_FUNCTION (this);
  26.123 +}
  26.124 +void 
  26.125 +NetlinkSocket::DoDispose (void)
  26.126 +{
  26.127 +  NS_LOG_FUNCTION_NOARGS ();
  26.128 +}
  26.129 +
  26.130 +int
  26.131 +NetlinkSocket::ErrnoToSimuErrno (void)
  26.132 +{
  26.133 +  switch (m_errno)
  26.134 +    {
  26.135 +    case Socket::ERROR_ISCONN:
  26.136 +      return EISCONN;
  26.137 +    case Socket::ERROR_NOTCONN:
  26.138 +      return ENOTCONN;
  26.139 +    case Socket::ERROR_MSGSIZE:
  26.140 +      return EMSGSIZE;
  26.141 +    case Socket::ERROR_AGAIN:
  26.142 +      return EAGAIN;
  26.143 +    case Socket::ERROR_SHUTDOWN:
  26.144 +      return ESHUTDOWN;
  26.145 +    case Socket::ERROR_OPNOTSUPP:
  26.146 +      return EOPNOTSUPP;
  26.147 +    case Socket::ERROR_AFNOSUPPORT:
  26.148 +      return EAFNOSUPPORT;
  26.149 +    case Socket::ERROR_INVAL:
  26.150 +      return EINVAL;
  26.151 +    case Socket::ERROR_BADF:
  26.152 +      return EBADF;
  26.153 +    case Socket::ERROR_NOROUTETOHOST:
  26.154 +      return EHOSTUNREACH;
  26.155 +    case Socket::ERROR_NODEV:
  26.156 +      return ENODEV;
  26.157 +    case Socket::ERROR_ADDRNOTAVAIL:
  26.158 +      return EADDRNOTAVAIL;
  26.159 +    case Socket::SOCKET_ERRNO_LAST:
  26.160 +    case Socket::ERROR_NOTERROR:
  26.161 +    default:
  26.162 +      NS_ASSERT (false);
  26.163 +      return 0; // quiet compiler
  26.164 +      break;
  26.165 +    }
  26.166 +}
  26.167 +
  26.168 +void 
  26.169 +NetlinkSocket::SetNode (Ptr<Node> node)
  26.170 +{
  26.171 +  NS_LOG_FUNCTION_NOARGS ();
  26.172 +  m_node = node;
  26.173 +}
  26.174 +
  26.175 +
  26.176 +enum Socket::SocketErrno
  26.177 +NetlinkSocket::GetErrno (void) const
  26.178 +{
  26.179 +  NS_LOG_FUNCTION_NOARGS ();
  26.180 +  return m_errno;
  26.181 +}
  26.182 +enum Socket::SocketType 
  26.183 +NetlinkSocket::GetSocketType (void) const
  26.184 +{
  26.185 +  return Socket::NS3_SOCK_DGRAM;
  26.186 +}
  26.187 +
  26.188 +Ptr<Node>
  26.189 +NetlinkSocket::GetNode (void) const
  26.190 +{
  26.191 +  NS_LOG_FUNCTION_NOARGS ();
  26.192 +  return m_node;
  26.193 +}
  26.194 +
  26.195 +uint32_t
  26.196 +NetlinkSocket::GetSrcPid (void) const
  26.197 +{
  26.198 +  NS_LOG_FUNCTION_NOARGS ();
  26.199 +  return m_srcPid;
  26.200 +}
  26.201 +uint32_t
  26.202 +NetlinkSocket::GetSrcGroups (void)const
  26.203 +{
  26.204 +  NS_LOG_FUNCTION_NOARGS ();
  26.205 +  return m_srcGroups;
  26.206 +}
  26.207 +uint32_t
  26.208 +NetlinkSocket::GetDstPid (void) const
  26.209 +{
  26.210 +  NS_LOG_FUNCTION_NOARGS ();
  26.211 +  return m_dstPid;
  26.212 +}
  26.213 +uint32_t
  26.214 +NetlinkSocket::GetDstGroups (void)const
  26.215 +{
  26.216 +  NS_LOG_FUNCTION_NOARGS ();
  26.217 +  return m_dstGroups;
  26.218 +}
  26.219 +
  26.220 +int
  26.221 +NetlinkSocket::Bind (void)
  26.222 +{
  26.223 +  NS_LOG_FUNCTION_NOARGS ();
  26.224 +  NetlinkSocketAddress address;
  26.225 +  return DoBind (address);
  26.226 +}
  26.227 +int
  26.228 +NetlinkSocket::Bind (const Address &address)
  26.229 +{ 
  26.230 +  NS_LOG_FUNCTION (this << address);
  26.231 +
  26.232 +  if (!NetlinkSocketAddress::IsMatchingType (address))
  26.233 +    {
  26.234 +      m_errno = ERROR_INVAL;
  26.235 +      return -1;
  26.236 +    }
  26.237 +  NetlinkSocketAddress ad = NetlinkSocketAddress::ConvertFrom (address);
  26.238 +  return DoBind (ad);
  26.239 +}
  26.240 +int
  26.241 +NetlinkSocket::DoBind (const NetlinkSocketAddress &address)
  26.242 +{
  26.243 +  NS_LOG_FUNCTION (this << address);
  26.244 +
  26.245 +  m_srcPid = address.GetProcessID ();
  26.246 +  m_srcGroups = address.GetGroupsMask ();
  26.247 +
  26.248 +  if (m_srcGroups)
  26.249 +    {
  26.250 +      GroupSockets::AddSocket(this);
  26.251 +    } 
  26.252 +  return 0;
  26.253 +}
  26.254 +
  26.255 +int 
  26.256 +NetlinkSocket::Listen (void)
  26.257 +{
  26.258 +  NS_LOG_FUNCTION_NOARGS ();
  26.259 +  m_errno = Socket::ERROR_OPNOTSUPP;
  26.260 +  return -1;
  26.261 +}
  26.262 +
  26.263 +uint32_t
  26.264 +NetlinkSocket::GetTxAvailable (void) const
  26.265 +{
  26.266 +  NS_LOG_FUNCTION_NOARGS ();
  26.267 +  return 0;
  26.268 +}
  26.269 +uint32_t
  26.270 +NetlinkSocket::GetRxAvailable (void) const
  26.271 +{
  26.272 +  NS_LOG_FUNCTION_NOARGS ();
  26.273 +  // We separately maintain this state to avoid walking the queue 
  26.274 +  // every time this might be called
  26.275 +  return m_rxAvailable;
  26.276 +}
  26.277 +
  26.278 +int
  26.279 +NetlinkSocket::ShutdownSend (void)
  26.280 +{
  26.281 +  NS_LOG_FUNCTION_NOARGS ();
  26.282 +  m_shutdownSend = true;
  26.283 +  return 0;
  26.284 +}
  26.285 +int
  26.286 +NetlinkSocket::ShutdownRecv (void)
  26.287 +{
  26.288 +  NS_LOG_FUNCTION_NOARGS ();
  26.289 +  m_shutdownRecv = true;
  26.290 +  return 0;
  26.291 +}
  26.292 +
  26.293 +int
  26.294 +NetlinkSocket::Close (void)
  26.295 +{
  26.296 +  NS_LOG_FUNCTION_NOARGS ();
  26.297 +  ShutdownSend();
  26.298 +  ShutdownRecv();
  26.299 +  return 0;
  26.300 +}
  26.301 +
  26.302 +int
  26.303 +NetlinkSocket::Connect (const Address &address)
  26.304 +{
  26.305 +  NS_LOG_FUNCTION (this << address);
  26.306 +  m_errno = Socket::ERROR_OPNOTSUPP;
  26.307 +  return 0;
  26.308 +}
  26.309 +
  26.310 +Ptr<Packet>
  26.311 +NetlinkSocket::Recv (uint32_t maxSize, uint32_t flags)
  26.312 +{
  26.313 +  NS_LOG_FUNCTION (this << maxSize<< flags);
  26.314 +  if (m_dataReceiveQueue.empty())
  26.315 +    {
  26.316 +      return 0;
  26.317 +    }
  26.318 +
  26.319 +  Ptr<Packet> p = m_dataReceiveQueue.front ();
  26.320 +  if (p->GetSize () <= maxSize) 
  26.321 +    {
  26.322 +      m_dataReceiveQueue.pop ();
  26.323 +      m_rxAvailable -= p->GetSize ();
  26.324 +    }
  26.325 +  else
  26.326 +    {
  26.327 +      p = 0; 
  26.328 +    }
  26.329 +  return p;
  26.330 +}
  26.331 +
  26.332 +Ptr<Packet>
  26.333 +NetlinkSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
  26.334 +{
  26.335 +  NS_LOG_FUNCTION (this << maxSize << flags << fromAddress);
  26.336 +  Ptr<Packet> packet = Recv (maxSize, flags);
  26.337 +  if (packet != 0)
  26.338 +    {
  26.339 +      SocketAddressTag tag;
  26.340 +      bool found;
  26.341 +      found = packet->FindFirstMatchingByteTag (tag);
  26.342 +      NS_ASSERT (found);
  26.343 +      fromAddress = tag.GetAddress ();
  26.344 +    }
  26.345 +  return packet;
  26.346 +}
  26.347 +
  26.348 +int
  26.349 +NetlinkSocket::Send (Ptr<Packet> p,uint32_t flags)
  26.350 +{
  26.351 +  NS_LOG_FUNCTION (this << p << flags);
  26.352 +  NetlinkSocketAddress address = NetlinkSocketAddress(m_dstPid, m_dstGroups);
  26.353 +  return SendTo(p, flags, address);
  26.354 +}
  26.355 +
  26.356 +int
  26.357 +NetlinkSocket::SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress)
  26.358 +{
  26.359 +  NS_LOG_FUNCTION (this << p << flags << toAddress);
  26.360 +  NetlinkSocketAddress ad;
  26.361 +
  26.362 +  if (!NetlinkSocketAddress::IsMatchingType (toAddress))
  26.363 +    {
  26.364 +      NS_LOG_LOGIC ("ERROR_AFNOSUPPORT");
  26.365 +      m_errno = ERROR_AFNOSUPPORT;
  26.366 +      return -1;
  26.367 +    }
  26.368 +  ad = NetlinkSocketAddress::ConvertFrom (toAddress);
  26.369 +  m_dstPid = ad.GetProcessID();
  26.370 +  m_dstGroups = ad.GetGroupsMask();
  26.371 +  NS_LOG_INFO ("send netlink message to pid = " << m_dstPid << ", groups = " << m_dstGroups);
  26.372 +  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending netlink message from " << m_node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ());
  26.373 +
  26.374 +  //Ptr<NetlinkSocket>kernel_socket = GetNetlinkSocketByAddress(ad);
  26.375 +  //kernel_socket->m_receivedData.push_back(p);
  26.376 +  //kernel_socket->NotifyDataReceived(p);
  26.377 +
  26.378 +  //when netlink socket send packet, the first step is to find the dest netlink socket through address
  26.379 +  //then send the packet to it. For we partly implement the netlink-family, the dest address
  26.380 +  //is always the kernel(pid = 0), (Actually, there must be one static kernel netlink socket to
  26.381 +  //receive/handle messages), we do not setup a kernel socket to receive packet.
  26.382 +  //
  26.383 +  
  26.384 +  MultipartNetlinkMessage multipartnlmsg;
  26.385 +  uint32_t packet_len, remain_len;
  26.386 +
  26.387 +  packet_len = p->GetSize ();
  26.388 +  remain_len = packet_len;
  26.389 +
  26.390 +  while (remain_len > NetlinkMessageHeader::GetHeaderSize ())
  26.391 +    {
  26.392 +      remain_len -= p->RemoveHeader (multipartnlmsg);
  26.393 +      NS_ASSERT (remain_len == p->GetSize ());
  26.394 +
  26.395 +      //actually, message to kernel contains single one netlink message
  26.396 +      for (uint32_t i = 0; i < multipartnlmsg.GetNMessages(); i ++)
  26.397 +        {
  26.398 +          NetlinkMessage nlmsg = multipartnlmsg.GetMessage (i);
  26.399 +          if (HandleMessage (nlmsg) < 0)
  26.400 +            {
  26.401 +              if (m_errno)
  26.402 +                {
  26.403 +                  SendAckMessage (nlmsg, -ErrnoToSimuErrno ());
  26.404 +                }
  26.405 +            }
  26.406 +          else if (NetlinkMessage::IsMessageFlagsAck (nlmsg.GetHeader ().GetMsgFlags ()))
  26.407 +            {
  26.408 +              SendAckMessage (nlmsg, 0);
  26.409 +            }
  26.410 +        }
  26.411 +    }
  26.412 +
  26.413 +  NotifyDataSent (packet_len);
  26.414 +  NS_LOG_INFO ("netlink socket kernel error " << -m_errno);
  26.415 +  return packet_len;
  26.416 +}
  26.417 +
  26.418 +int
  26.419 +NetlinkSocket::GetSockName (Address &address) const
  26.420 +{
  26.421 +  NS_LOG_FUNCTION_NOARGS ();
  26.422 +  NetlinkSocketAddress ad;
  26.423 +
  26.424 +  ad.SetProcessID (GetSrcPid ());
  26.425 +  ad.SetGroupsMask (GetSrcGroups ());
  26.426 +  address = ad;
  26.427 +  return 0;
  26.428 +}
  26.429 +int
  26.430 +NetlinkSocket::GetPeerName (Address &address) const
  26.431 +{
  26.432 +  NS_LOG_FUNCTION_NOARGS ();
  26.433 +  // XXX
  26.434 +  NS_ASSERT (false);
  26.435 +  return -1;
  26.436 +}
  26.437 +bool 
  26.438 +NetlinkSocket::SetAllowBroadcast (bool allowBroadcast)
  26.439 +{
  26.440 +  NS_ASSERT (false);
  26.441 +  return false;
  26.442 +}
  26.443 +bool 
  26.444 +NetlinkSocket::GetAllowBroadcast () const
  26.445 +{
  26.446 +  NS_ASSERT (false);
  26.447 +  return false;
  26.448 +}
  26.449 +
  26.450 +
  26.451 +void
  26.452 +NetlinkSocket::ForwardUp (Ptr<Packet> packet, NetlinkSocketAddress &address)
  26.453 +{
  26.454 +  NS_LOG_FUNCTION (this << packet << address);
  26.455 +
  26.456 +  if (m_shutdownRecv)
  26.457 +    {
  26.458 +      return;
  26.459 +    }
  26.460 +  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
  26.461 +    {
  26.462 +      SocketAddressTag tag;
  26.463 +      tag.SetAddress (address);
  26.464 +      packet->AddByteTag (tag);
  26.465 +      m_dataReceiveQueue.push (packet);
  26.466 +      m_rxAvailable += packet->GetSize ();
  26.467 +      NotifyDataRecv ();
  26.468 +    }
  26.469 +  else
  26.470 +    {
  26.471 +      NS_LOG_WARN ("No receive buffer space available.  Drop.");
  26.472 +      m_dropTrace (packet);
  26.473 +    }
  26.474 +}
  26.475 +
  26.476 +int32_t
  26.477 +NetlinkSocket::SendMessageUnicast (const MultipartNetlinkMessage &nlmsg, uint32_t pid, int32_t nonblock)
  26.478 +{
  26.479 +  NS_LOG_FUNCTION (this << pid << nonblock);
  26.480 +  //here we send message instantly
  26.481 +  Ptr<Packet> p = Create<Packet> ();
  26.482 +  p->AddHeader (nlmsg);
  26.483 +
  26.484 +  NetlinkSocketAddress address;
  26.485 +  address.SetProcessID (pid);
  26.486 +
  26.487 +  //send packet to user space
  26.488 +  ForwardUp (p, address);
  26.489 +  return 0;
  26.490 +}
  26.491 +int32_t
  26.492 +NetlinkSocket::SendMessageBroadcast (const MultipartNetlinkMessage &nlmsg, 
  26.493 +                                     uint32_t pid, 
  26.494 +                                     uint32_t group,
  26.495 +                                     Ptr<Node> node)
  26.496 +{
  26.497 +  NS_LOG_FUNCTION ("SendMessageBroadcast" << pid << group);
  26.498 +  //fisrt find the dest netlink socket through group value, then attach this nlmsg to its recv-queue
  26.499 +  for (uint32_t i = 0; i < GroupSockets::GetNSockets (); i ++)
  26.500 +    {
  26.501 +      Ptr<NetlinkSocket> nlsock = GroupSockets::GetSocket (i);
  26.502 +
  26.503 +      if ((nlsock->GetSrcGroups () & group) &&
  26.504 +          (nlsock->GetSrcPid () != pid) &&
  26.505 +          node == nlsock->GetNode ())
  26.506 +        {
  26.507 +          //here we send message instantly
  26.508 +          Ptr<Packet> p = Create<Packet> ();
  26.509 +          p->AddHeader (nlmsg);
  26.510 +
  26.511 +          NetlinkSocketAddress address;
  26.512 +          address.SetProcessID (nlsock->GetSrcPid());
  26.513 +          address.SetGroupsMask (group);
  26.514 +
  26.515 +          //send packet to user space
  26.516 +          nlsock->ForwardUp (p, address);
  26.517 +        }
  26.518 +    }
  26.519 +  return 0;
  26.520 +}
  26.521 +void
  26.522 +NetlinkSocket::SendAckMessage (const NetlinkMessage&nlmsg, int32_t err)
  26.523 +{
  26.524 +  NS_LOG_FUNCTION (this << err);
  26.525 +  NetlinkMessageHeader rep;
  26.526 +  NetlinkMessage ackmsg;
  26.527 +  NetlinkMessageError errmsg;
  26.528 +
  26.529 +  rep.SetMsgPid (nlmsg.GetHeader ().GetMsgPid ());
  26.530 +  rep.SetMsgSeq (nlmsg.GetHeader ().GetMsgSeq ());
  26.531 +  rep.SetMsgType (NETLINK_MSG_ERROR);
  26.532 +  rep.SetMsgFlags (0);
  26.533 +
  26.534 +  errmsg.SetError (err);
  26.535 +  //kernel send the whole nlmsg back if error != 0, here we just send the header back
  26.536 +  errmsg.SetMsg (nlmsg.GetHeader ());
  26.537 +
  26.538 +  //then send errmsg back to user space
  26.539 +  ackmsg.SetHeader (rep);
  26.540 +  ackmsg.SetErrorMessage (errmsg);
  26.541 +
  26.542 +  SendMessageUnicast (ackmsg, rep.GetMsgPid (), 1);
  26.543 +}
  26.544 +
  26.545 +int32_t
  26.546 +NetlinkSocket::HandleMessage (const NetlinkMessage&nlmsg)
  26.547 +{
  26.548 +  NS_LOG_FUNCTION (this);
  26.549 +  uint16_t type = nlmsg.GetMsgType ();
  26.550 +  NetlinkMessageHeader nhr = nlmsg.GetHeader ();
  26.551 +
  26.552 +  if (nhr.GetMsgLen () < NetlinkMessageHeader::GetHeaderSize ())
  26.553 +    {
  26.554 +      m_errno = ERROR_INVAL;
  26.555 +      return -1;
  26.556 +    }
  26.557 +
  26.558 +  if (NetlinkMessage::IsMessageNetlinkControl (type))
  26.559 +    {
  26.560 +      NS_LOG_INFO ("netlink control message type not parsed in kernel");
  26.561 +      return 0;
  26.562 +    }
  26.563 +  else if (NetlinkMessage::IsMessageNetlinkRoute (type))
  26.564 +    {
  26.565 +      return HandleNetlinkRouteMessage (nlmsg);
  26.566 +    }
  26.567 +  else
  26.568 +    {
  26.569 +      NS_LOG_INFO ("netlink message type not parsed in kernel");
  26.570 +      m_errno = ERROR_INVAL;
  26.571 +      return -1;
  26.572 +    }  
  26.573 +}
  26.574 +
  26.575 +int32_t
  26.576 +NetlinkSocket::HandleNetlinkRouteMessage (const NetlinkMessage &nlmsg)
  26.577 +{
  26.578 +  NS_LOG_FUNCTION (this);
  26.579 +  uint8_t family;
  26.580 +  int16_t type;
  26.581 +  int32_t err;
  26.582 +
  26.583 +  /* Only requests are handled by kernel now */
  26.584 +  if (!NetlinkMessage::IsMessageFlagsRequest (nlmsg.GetHeader ().GetMsgFlags ()))
  26.585 +    return 0;
  26.586 +
  26.587 +  type = nlmsg.GetMsgType ();
  26.588 +
  26.589 +  /* A control message: ignore them */
  26.590 +  if (NetlinkMessage::IsMessageNetlinkControl (type))
  26.591 +    {
  26.592 +      return 0;
  26.593 +    }
  26.594 +  else if (NetlinkMessage::IsMessageNetlinkRoute (type))
  26.595 +    {
  26.596 +      /* All the messages must have at least 1 byte length */
  26.597 +      if (nlmsg.GetPayloadSize () < 1)
  26.598 +        return 0;
  26.599 +
  26.600 +      family = nlmsg.GetFamily ();
  26.601 +      /*here we do not deal with different family, default for AF_NET*/
  26.602 +      NS_ASSERT(family == AF_INET || family == AF_UNSPEC || family == AF_PACKET || family == AF_INET6);  
  26.603 +
  26.604 +      /*for GET*** message, dump it to userspace*/
  26.605 +      if (NetlinkMessage::IsMessageTypeGet (type) && 
  26.606 +          NetlinkMessage::IsMessageFlagsDump (nlmsg.GetHeader ().GetMsgFlags ())) 
  26.607 +        {
  26.608 +          DumpNetlinkRouteMessage (nlmsg, type, family);
  26.609 +          return -1;
  26.610 +        }
  26.611 +
  26.612 +      /* other types of messages*/
  26.613 +      return DoNetlinkRouteMessage (nlmsg, type, family);
  26.614 +    }
  26.615 +  else/* Unknown message: reply with EINVAL */
  26.616 +    {
  26.617 +      err = ERROR_INVAL;
  26.618 +      return -1;
  26.619 +    } 
  26.620 +}
  26.621 +
  26.622 +int32_t
  26.623 +NetlinkSocket::DumpNetlinkRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  26.624 +{
  26.625 +  NS_LOG_FUNCTION (this << type << family);
  26.626 +
  26.627 +  NS_ASSERT (type == NETLINK_RTM_GETADDR || type == NETLINK_RTM_GETROUTE || type == NETLINK_RTM_GETLINK);
  26.628 +
  26.629 +  MultipartNetlinkMessage nlmsg_dump;
  26.630 +  NetlinkMessageHeader nhr = nlmsg.GetHeader ();
  26.631 +  int32_t err;
  26.632 +
  26.633 +  if (type == NETLINK_RTM_GETADDR)
  26.634 +    {
  26.635 +      nlmsg_dump = BuildInterfaceAddressDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);
  26.636 +    }
  26.637 +  else if (type == NETLINK_RTM_GETLINK)
  26.638 +    {
  26.639 +      nlmsg_dump = BuildInterfaceInfoDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);      
  26.640 +    }
  26.641 +  else if (type == NETLINK_RTM_GETROUTE)
  26.642 +    {
  26.643 +      nlmsg_dump = BuildRouteDumpMessage (m_srcPid, nhr.GetMsgSeq(), family);
  26.644 +    }
  26.645 +  else
  26.646 +    {
  26.647 +      m_errno = ERROR_INVAL;
  26.648 +      return -1;
  26.649 +    }
  26.650 +
  26.651 +  //then append netlink message with type NLMSG_DONE
  26.652 +  NetlinkMessage nlmsg_done;
  26.653 +  NetlinkMessageHeader nhr2 = NetlinkMessageHeader (NETLINK_MSG_DONE, NETLINK_MSG_F_MULTI, 
  26.654 +                                                   nlmsg.GetHeader ().GetMsgSeq (), m_srcPid);
  26.655 +  nlmsg_done.SetHeader (nhr2);
  26.656 +  //kernel append nlmsg_dump size to it, here we omit it
  26.657 +  nlmsg_dump.AppendMessage (nlmsg_done);
  26.658 +
  26.659 +  err = SendMessageUnicast (nlmsg_dump, m_srcPid, 1);
  26.660 +  return err;
  26.661 +}
  26.662 +
  26.663 +/*here only for ADD/DEL/GET*** types*/
  26.664 +int32_t
  26.665 +NetlinkSocket::DoNetlinkRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8_t family)
  26.666 +{
  26.667 +  NS_LOG_FUNCTION (this << type <<family);
  26.668 +  int32_t err;
  26.669 +
  26.670 +  if (type == NETLINK_RTM_NEWADDR || type == NETLINK_RTM_DELADDR)
  26.671 +    {      
  26.672 +      err = DoInterfaceAddressMessage (nlmsg, type, family);
  26.673 +    }
  26.674 +  else if (type == NETLINK_RTM_NEWROUTE || type == NETLINK_RTM_DELROUTE || type == NETLINK_RTM_GETROUTE)
  26.675 +    {     
  26.676 +      err = DoRouteMessage (nlmsg, type, family);
  26.677 +    }
  26.678 +  else if (type == NETLINK_RTM_GETLINK || type == NETLINK_RTM_SETLINK)
  26.679 +    {     
  26.680 +      err = DoInterfaceInfoMessage (nlmsg, type, family);
  26.681 +    }
  26.682 +  else
  26.683 +    {
  26.684 +      NS_LOG_LOGIC ("netlink message:type( " << type << ") not processed by ns3 now." );
  26.685 +      m_errno = ERROR_INVAL;
  26.686 +      err = -1;
  26.687 +    } 
  26.688 +  
  26.689 +  return err;
  26.690 +}
  26.691 +
  26.692 +MultipartNetlinkMessage
  26.693 +NetlinkSocket::BuildInterfaceAddressDumpMessage (uint32_t pid, uint32_t seq, uint8_t family)
  26.694 +{
  26.695 +  NS_LOG_FUNCTION (this << pid << seq <<family);
  26.696 +  MultipartNetlinkMessage nlmsg_dump;
  26.697 +  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
  26.698 +
  26.699 +  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++)
  26.700 +    {
  26.701 +      if (!ipv4->IsUp (i))
  26.702 +        continue;
  26.703 +
  26.704 +      Ipv4Address addri = ipv4->GetAddress (i, 0).GetLocal ();
  26.705 +      Ipv4Mask maski = ipv4->GetAddress (i, 0).GetMask ();
  26.706 +      Ipv4Address bcast = ipv4->GetAddress (i, 0).GetBroadcast ();
  26.707 +
  26.708 +      //here get the address mask length
  26.709 +      uint32_t mask = maski.Get ();
  26.710 +      uint8_t mask_len = 0;
  26.711 +      while (mask)
  26.712 +        {
  26.713 +          mask = mask << 1;
  26.714 +          mask_len ++;
  26.715 +        }
  26.716 +      
  26.717 +      //next fill the message body
  26.718 +      NetlinkMessage nlmsg_ifa;
  26.719 +      NetlinkMessageHeader nhr = NetlinkMessageHeader (NETLINK_RTM_NEWADDR, NETLINK_MSG_F_MULTI, seq, pid);
  26.720 +      InterfaceAddressMessage ifamsg;
  26.721 +
  26.722 +      ifamsg.SetInterfaceIndex (i);
  26.723 +      ifamsg.SetFamily (AF_INET);//default AF_INET