A Discrete-Event Network Simulator
API
cid-factory.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008,2009 INRIA, UDcast
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  * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20  * <amine.ismail@UDcast.com>
21  */
22 
23 
24 #include <stdint.h>
25 #include "cid-factory.h"
26 #include "ns3/uinteger.h"
27 
28 namespace ns3 {
29 
31  : m_m (0x5500),
32  // this is an arbitrary default
33  m_basicIdentifier (1),
34  m_primaryIdentifier (m_m + 1),
35  m_transportOrSecondaryIdentifier (2 * m_m + 1),
36  m_multicastPollingIdentifier (0xff00)
37 {
38 }
39 
40 Cid
42 {
45  return Cid (m_basicIdentifier);
46 }
47 
48 Cid
50 {
53  return Cid (m_primaryIdentifier);
54 }
55 
56 Cid
58 {
62 }
63 
64 Cid
66 {
70 }
71 
72 
73 Cid
75 {
76  switch (type)
77  {
78  case Cid::BROADCAST:
79  return Cid::Broadcast ();
81  return Cid::InitialRanging ();
82  case Cid::BASIC:
83  return AllocateBasic ();
84  case Cid::PRIMARY:
85  return AllocatePrimary ();
86  case Cid::TRANSPORT:
88  case Cid::MULTICAST:
89  return AllocateMulticast ();
90  case Cid::PADDING:
91  return Cid::Padding ();
92  default:
93  NS_FATAL_ERROR ("Cannot be reached");
94  return 0; // quiet compiler
95  }
96 }
97 
98 bool
100 {
101  int id = cid.m_identifier;
102  return (id - 2 * m_m > 0) && (id <= 0xfefe);
103 }
104 bool
106 {
107  int id = cid.m_identifier;
108  return (id - m_m > 0) && (id <= 2 * m_m);
109 }
110 bool
112 {
113  uint16_t id = cid.m_identifier;
114  return id >= 1 && id <= m_m;
115 }
116 
117 
118 void
120 {
122  NS_FATAL_ERROR ("TODO: Update the cid bitmap properly here-- please implement and contribute a patch");
123 }
124 
125 } // namespace ns3
126 
127 
CidFactory(void)
Create a cid factory with a default value for m of 0x5500.
Definition: cid-factory.cc:30
uint16_t m_basicIdentifier
Definition: cid-factory.h:88
Cid AllocateBasic(void)
This function returns the next basic CID.
Definition: cid-factory.cc:41
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
uint16_t m_identifier
Definition: cid.h:89
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
bool IsBasic(Cid cid) const
Definition: cid-factory.cc:111
static Cid Broadcast(void)
Definition: cid.cc:72
static Cid InitialRanging(void)
Definition: cid.cc:82
uint16_t m_multicastPollingIdentifier
Definition: cid-factory.h:91
void FreeCid(Cid cid)
Notify the factory that the connection associated to this cid has been killed and that this cid can b...
Definition: cid-factory.cc:119
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Cid AllocatePrimary(void)
This function returns the next primary basic CID.
Definition: cid-factory.cc:49
static Cid Padding(void)
Definition: cid.cc:77
Definition: cid.h:35
uint16_t m_transportOrSecondaryIdentifier
Definition: cid-factory.h:90
uint16_t m_m
Definition: cid-factory.h:86
bool IsTransport(Cid cid) const
Definition: cid-factory.cc:99
Cid AllocateMulticast(void)
This function returns the next Multicast CID.
Definition: cid-factory.cc:65
Cid Allocate(enum Cid::Type type)
Definition: cid-factory.cc:74
Cid AllocateTransportOrSecondary(void)
This function returns the next Transport (or Secondary) CID.
Definition: cid-factory.cc:57
bool IsPrimary(Cid cid) const
Definition: cid-factory.cc:105
Type
Definition: cid.h:38
uint16_t m_primaryIdentifier
Definition: cid-factory.h:89