libDwm-0.6.0
DwmLLCAT.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmLLCAT.hh 8401 $
3 // @(#) $Id: DwmLLCAT.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2006
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMLLCAT_HH_
43 #define _DWMLLCAT_HH_
44 
45 extern "C" {
46  #include <inttypes.h>
47 }
48 
49 #include <vector>
50 
51 namespace Dwm {
52 
53  template <typename DataType> class LLCATNode;
54 
55  //--------------------------------------------------------------------------
57  //--------------------------------------------------------------------------
58  template <typename DataType>
59  class LLCATSegment
60  {
61  public:
62  LLCATSegment<DataType>(uint8_t K)
63  : _K(K), _bits(0), _route(0), _forwardPointer(0)
64  {}
65 
66  // 1 bit
67  inline bool StopBit() const
68  {
69  return(_bits & 0x00000001);
70  }
71 
72  // 1 bit
73  bool StopBit(bool on)
74  {
75  if (on)
76  _bits |= 0x00000001;
77  else
78  _bits &= ~(0x00000001);
79  return(on);
80  }
81 
82  // 1 bit
83  bool ValidBit() const
84  {
85  return(_bits & 0x00000002);
86  }
87 
88  // 1 bit
89  bool ValidBit(bool on)
90  {
91  if (on)
92  _bits |= 0x00000002;
93  else
94  _bits &= ~(0x00000002);
95  return(on);
96  }
97 
98  // 1 bit
99  bool FullPrefixRoute() const
100  {
101  return(_bits & 0x00000004);
102  }
103 
104  // 1 bit
105  bool FullPrefixRoute(bool on)
106  {
107  if (on)
108  _bits |= 0x00000004;
109  else
110  _bits &= ~(0x00000004);
111  return(on);
112  }
113 
114  // (_K - 1) bits
115  uint8_t LifeChildrenCounter() const
116  {
117  uint8_t mask = 0;
118  for (uint8_t i = 0; i < (_K - 1); ++i) {
119  mask |= (1 << i);
120  }
121  uint8_t rc = (_bits >> 3) & mask;
122  return(rc);
123  }
124 
125  uint8_t LifeChildrenCounter(uint8_t lcc)
126  {
127  uint32_t mask = 0;
128  for (uint8_t i = 0; i < (_K - 1); ++i) {
129  mask |= (1 << i);
130  }
131 
132  // clear the old bits
133  mask <<= 3;
134  _bits &= ~(mask);
135  // then set them
136  _bits |= ((uint32_t)lcc << 3);
137 
138  uint8_t rc = (_bits & mask) >> 3;
139  return(rc);
140  }
141 
142  const DataType *Route() const
143  {
144  return(_route);
145  }
146 
147  DataType *Route()
148  {
149  return(_route);
150  }
151 
152  DataType *Route(DataType *route)
153  {
154  _route = route;
155  return(_route);
156  }
157 
158  // (K - 1) bits
159  uint8_t ValidSubPrefixPattern() const
160  {
161  uint8_t mask = 0;
162  for (uint8_t i = 0; i < (_K - 1); ++i) {
163  mask |= (1 << i);
164  }
165  uint8_t rc = ((_bits >> (3 + (_K - 1))) & mask);
166  return(rc);
167 
168  }
169 
170  uint8_t ValidSubPrefixPattern(uint8_t vsp)
171  {
172  uint32_t mask = 0;
173  for (uint8_t i = 0; i < (_K - 1); ++i) {
174  mask |= (1 << i);
175  }
176 
177  // clear the old bits
178  mask <<= 3 + (_K - 1);
179  _bits &= ~(mask);
180  // then set them
181  _bits |= ((uint32_t)vsp << (3 + (_K - 1)));
182 
183  uint8_t rc = (_bits & mask) >> (3 + (_K - 1));
184  return(rc);
185  }
186 
187  const LLCATNode<DataType> *ForwardPointer() const
188  {
189  return(_forwardPointer);
190  }
191 
192  const LLCATNode<DataType> *ForwardPointer(LLCATNode<DataType> *fp)
193  {
194  _forwardPointer = fp;
195  return(_forwardPointer);
196  }
197 
198  private:
199  uint8_t _K;
200  uint32_t _bits;
201  DataType *_route;
202  LLCATNode<DataType> *_forwardPointer;
203  };
204 
205 
206 
207 
208 
209  //--------------------------------------------------------------------------
211  //--------------------------------------------------------------------------
212  template <typename DataType>
213  class LLCATNode
214  {
215  public:
216  LLCATNode<DataType>(uint8_t K)
217  : _segments(((uint32_t)1 << K), LLCATSegment<DataType>(K))
218  {
219 
220  }
221 
222  private:
223  std::vector<LLCATSegment<DataType> > _segments;
224  };
225 
226 
227 
228 
229 
230  //--------------------------------------------------------------------------
232  //--------------------------------------------------------------------------
233  template <typename DataType>
234  class Ipv4LLCAT
235  {
236  };
237 
238 
239 
240 
241 
242  //--------------------------------------------------------------------------
244  //--------------------------------------------------------------------------
245  template <typename DataType>
246  class Ipv6LLCAT
247  {
248  };
249 
250 
251 } // namespace Dwm
252 
253 #endif // _DWMLLCAT_HH_
254 
255 //---------------------------- emacs settings -----------------------------
256 // Local Variables:
257 // mode: C++/la
258 // tab-width: 2
259 // indent-tabs-mode: nil
260 // c-basic-offset: 2
261 // End:
262 //-------------------------------------------------------------------------
Definition: DwmBZ2IO.hh:67