netlink/netlink-attribute.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 05 May 2011 09:28:21 +0200
changeset 66 2fe1f3e576c9
parent 63 model/netlink-attribute.h@e89dca438df6
permissions -rw-r--r--
make it somewhat build sanely
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2008 Liu Jian
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Liu Jian <liujatp@gmail.com>
    19  *         Hajime Tazaki <tazaki@sfc.wide.ad.jp>
    20  */
    21 
    22 #ifndef NETLINK_ATTRIBUTE_H
    23 #define NETLINK_ATTRIBUTE_H
    24 
    25 
    26 #include <stdint.h>
    27 #include <string>
    28 #include <ostream>
    29 #include "ns3/address.h"
    30 #include "ns3/buffer.h"
    31 
    32 namespace ns3 {
    33 
    34 /**
    35 * \brief The Netlink Attribute
    36 */
    37 
    38 typedef enum NetlinkAttributeValueType_e {
    39   UNSPEC, // invalid initial value.
    40   U8,
    41   U16,
    42   U32,
    43   U64,
    44   STRING,
    45   ADDRESS,
    46 }NetlinkAttributeValueType;
    47 
    48 class NetlinkAttributeValue
    49 {
    50 public:
    51   NetlinkAttributeValue ();
    52   NetlinkAttributeValue (NetlinkAttributeValueType type, uint8_t v);
    53   NetlinkAttributeValue (NetlinkAttributeValueType type, uint16_t v);
    54   NetlinkAttributeValue (NetlinkAttributeValueType type, uint32_t v);
    55   NetlinkAttributeValue (NetlinkAttributeValueType type, uint64_t v);
    56   NetlinkAttributeValue (NetlinkAttributeValueType type, std::string v);
    57   NetlinkAttributeValue (NetlinkAttributeValueType type, Address v);
    58   
    59   void Serialize (Buffer::Iterator& start) const;
    60   uint32_t DeserializeWithType (Buffer::Iterator& start, NetlinkAttributeValueType type, uint16_t remaining);
    61   uint32_t GetSerializedSize (void) const;
    62   uint32_t GetSize (void) const;
    63   void Print (std::ostream &os) const;
    64 
    65   void SetType (NetlinkAttributeValueType type);
    66   NetlinkAttributeValueType GetType (void) const;
    67   void SetAddress (Address value);
    68   void SetString (std::string value);
    69   void SetU64 (uint64_t value);
    70   void SetU32 (uint32_t value);
    71   void SetU16 (uint16_t value);
    72   void SetU8 (uint8_t value);
    73   Address GetAddress (void) const;
    74   std::string GetString (void) const;
    75   uint64_t GetU64 (void) const;
    76   uint32_t GetU32 (void) const;
    77   uint16_t GetU16 (void) const;
    78   uint8_t GetU8 (void) const;
    79 
    80 private:
    81   NetlinkAttributeValueType m_type;
    82   uint64_t m_u64;
    83   uint32_t m_u32;
    84   uint16_t m_u16;
    85   uint8_t m_u8;
    86   std::string m_string;
    87   Address m_address;
    88 };
    89 
    90 struct NetlinkAttribute
    91 {
    92 public:
    93   NetlinkAttribute ();
    94   NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint8_t payload);
    95   NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint16_t payload);
    96   NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint32_t payload);
    97   NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  uint64_t payload);
    98   NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  std::string payload);
    99   NetlinkAttribute (uint16_t type, NetlinkAttributeValueType payloadtype,  Address payload);
   100 
   101   //static TypeId GetTypeId (void);
   102   //virtual TypeId GetInstanceTypeId (void) const;
   103   void Print (std::ostream &os) const;
   104   uint32_t GetSerializedSize (void) const;
   105   void Serialize (Buffer::Iterator& start) const;
   106   uint32_t Deserialize (Buffer::Iterator& start, NetlinkAttributeValueType vtypes[]);
   107 
   108   void SetAttrLen (uint16_t v);
   109   void SetAttrType (uint16_t v);
   110   void SetAttrPayload (NetlinkAttributeValue v);
   111   uint16_t GetAttrLen () const;
   112   uint16_t GetAttrType () const;
   113   NetlinkAttributeValue GetAttrPayload () const;
   114 
   115 private:
   116   static const int NETLINK_MSG_ATTR_SIZE = 4; /* size of the nlattr field*/
   117   uint16_t m_len;
   118   uint16_t m_type; 
   119   NetlinkAttributeValue m_payload;
   120 };
   121 
   122 }; // namespace ns3
   123 
   124 #endif /* NETLINK_ATTRIBUTE_H */