src/internet/model/ipv4-interface-address.h
changeset 10440 1e48ff9185f1
parent 7385 10beb0e53130
equal deleted inserted replaced
10439:73bc9e55f9bd 10440:1e48ff9185f1
    40  * documentation for this distinction.
    40  * documentation for this distinction.
    41  */
    41  */
    42 class Ipv4InterfaceAddress 
    42 class Ipv4InterfaceAddress 
    43 {
    43 {
    44 public:
    44 public:
       
    45   /**
       
    46    * \enum InterfaceAddressScope_e
       
    47    * \brief Address scope.
       
    48    */
    45   enum InterfaceAddressScope_e {
    49   enum InterfaceAddressScope_e {
    46     HOST,
    50     HOST,
    47     LINK,
    51     LINK,
    48     GLOBAL
    52     GLOBAL
    49   };
    53   };
    50 
    54 
    51   Ipv4InterfaceAddress ();
    55   Ipv4InterfaceAddress ();
    52   // Configure m_local, m_mask, and m_broadcast from the below constructor
    56 
       
    57   /**
       
    58    * \brief Configure local address, mask and broadcast address
       
    59    * \param local the local address
       
    60    * \param mask the network mask
       
    61    */
    53   Ipv4InterfaceAddress (Ipv4Address local, Ipv4Mask mask);
    62   Ipv4InterfaceAddress (Ipv4Address local, Ipv4Mask mask);
       
    63   /**
       
    64    * Copy constructor
       
    65    * \param o the object to copy
       
    66    */
    54   Ipv4InterfaceAddress (const Ipv4InterfaceAddress &o);
    67   Ipv4InterfaceAddress (const Ipv4InterfaceAddress &o);
    55 
    68 
       
    69   /**
       
    70    * \brief Set local address
       
    71    * \param local the address
       
    72    */
    56   void SetLocal (Ipv4Address local);
    73   void SetLocal (Ipv4Address local);
       
    74   /**
       
    75    * \brief Get the local address
       
    76    * \returns the local address
       
    77    */
    57   Ipv4Address GetLocal (void) const;
    78   Ipv4Address GetLocal (void) const;
       
    79   /**
       
    80    * \brief Set the network mask
       
    81    * \param mask the network mask
       
    82    */
    58   void SetMask (Ipv4Mask mask);
    83   void SetMask (Ipv4Mask mask);
       
    84   /**
       
    85    * \brief Get the network mask
       
    86    * \returns the network mask
       
    87    */
    59   Ipv4Mask GetMask (void) const;
    88   Ipv4Mask GetMask (void) const;
       
    89   /**
       
    90    * \brief Set the broadcast address
       
    91    * \param broadcast the broadcast address
       
    92    */
    60   void SetBroadcast (Ipv4Address broadcast);
    93   void SetBroadcast (Ipv4Address broadcast);
       
    94   /**
       
    95    * \brief Get the broadcast address
       
    96    * \returns the broadcast address
       
    97    */
    61   Ipv4Address GetBroadcast (void) const;
    98   Ipv4Address GetBroadcast (void) const;
    62  
    99  
       
   100   /**
       
   101    * \brief Set the scope.
       
   102    * \param scope the scope of address
       
   103    */
    63   void SetScope (Ipv4InterfaceAddress::InterfaceAddressScope_e scope);
   104   void SetScope (Ipv4InterfaceAddress::InterfaceAddressScope_e scope);
       
   105 
       
   106   /**
       
   107    * \brief Get address scope.
       
   108    * \return scope
       
   109    */
    64   Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope (void) const;
   110   Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope (void) const;
    65 
   111 
       
   112   /**
       
   113    * \brief Check if the address is a secondary address
       
   114    *
       
   115    * Secondary address is used for multihoming
       
   116    * \returns true if the address is secondary
       
   117    */
    66   bool IsSecondary (void) const;
   118   bool IsSecondary (void) const;
       
   119 
       
   120   /**
       
   121    * \brief Make the address secondary (used for multihoming)
       
   122    */
    67   void SetSecondary (void);
   123   void SetSecondary (void);
       
   124   /**
       
   125    * \brief Make the address primary
       
   126    */
    68   void SetPrimary (void);
   127   void SetPrimary (void);
    69 
   128 
    70 private:
   129 private:
    71 
   130 
    72   Ipv4Address m_local;     // Interface address
   131   Ipv4Address m_local;     //!< Interface address
    73   // Note:  m_peer may be added in future when necessary
   132   // Note:  m_peer may be added in future when necessary
    74   // Ipv4Address m_peer;      // Peer destination address (in Linux:  m_address)
   133   // Ipv4Address m_peer;   // Peer destination address (in Linux:  m_address)
    75   Ipv4Mask m_mask;         // Network mask
   134   Ipv4Mask m_mask;         //!< Network mask
    76   Ipv4Address m_broadcast; // Broadcast address
   135   Ipv4Address m_broadcast; //!< Broadcast address
    77 
   136 
    78   InterfaceAddressScope_e m_scope;
   137   InterfaceAddressScope_e m_scope; //!< Address scope
    79   bool m_secondary;        // For use in multihoming
   138   bool m_secondary;        //!< For use in multihoming
    80 
   139 
       
   140   /**
       
   141    * \brief Equal to operator.
       
   142    *
       
   143    * \param a the first operand
       
   144    * \param b the first operand
       
   145    * \returns true if the operands are equal
       
   146    */
    81   friend bool operator == (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b);
   147   friend bool operator == (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b);
       
   148 
       
   149   /**
       
   150    * \brief Not equal to operator.
       
   151    *
       
   152    * \param a the first operand
       
   153    * \param b the first operand
       
   154    * \returns true if the operands are not equal
       
   155    */
    82   friend bool operator != (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b);
   156   friend bool operator != (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b);
    83 };
   157 };
    84 
   158 
       
   159 /**
       
   160  * \brief Stream insertion operator.
       
   161  *
       
   162  * \param os the reference to the output stream
       
   163  * \param addr the Ipv4InterfaceAddress
       
   164  * \returns the reference to the output stream
       
   165  */
    85 std::ostream& operator<< (std::ostream& os, const Ipv4InterfaceAddress &addr);
   166 std::ostream& operator<< (std::ostream& os, const Ipv4InterfaceAddress &addr);
    86 
   167 
    87 inline bool operator == (const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
   168 inline bool operator == (const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
    88 {
   169 {
    89   return (a.m_local == b.m_local && a.m_mask == b.m_mask &&
   170   return (a.m_local == b.m_local && a.m_mask == b.m_mask &&