libDwm-0.6.0
DwmMplsLabel.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmMplsLabel.hh 8401 $
3 // @(#) $Id: DwmMplsLabel.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2007, 2016
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 #ifndef _DWMMPLSLABEL_HH_
42 #define _DWMMPLSLABEL_HH_
43 
44 
45 #include "DwmBZ2Readable.hh"
46 #include "DwmBZ2Writable.hh"
47 #include "DwmGZReadable.hh"
48 #include "DwmGZWritable.hh"
49 #include "DwmReadable.hh"
50 #include "DwmWritable.hh"
51 
52 namespace Dwm {
53 
54  //--------------------------------------------------------------------------
56  //--------------------------------------------------------------------------
57  class MplsLabel
58  : public Readable, public Writable,
59  public GZReadable, public GZWritable,
60  public BZ2Readable, public BZ2Writable
61  {
62  public:
63  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
66  MplsLabel();
67 
68  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
71  MplsLabel(const std::string & s);
72 
73  //------------------------------------------------------------------------
75  //------------------------------------------------------------------------
76  uint32_t Label() const;
77 
78  //------------------------------------------------------------------------
80  //------------------------------------------------------------------------
81  uint32_t Label(uint32_t label);
82 
83  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
86  uint8_t Exp() const;
87 
88  //------------------------------------------------------------------------
90  //------------------------------------------------------------------------
91  uint8_t Exp(uint8_t exp);
92 
93  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  bool S() const;
97 
98  //------------------------------------------------------------------------
100  //------------------------------------------------------------------------
101  bool S(bool s);
102 
103  //------------------------------------------------------------------------
105  //------------------------------------------------------------------------
106  uint8_t Ttl() const;
107 
108  //------------------------------------------------------------------------
110  //------------------------------------------------------------------------
111  uint8_t Ttl(uint8_t ttl);
112 
113  //------------------------------------------------------------------------
115  //------------------------------------------------------------------------
116  bool operator == (const MplsLabel & label) const;
117 
118  //------------------------------------------------------------------------
120  //------------------------------------------------------------------------
121  std::istream & Read(std::istream & is);
122 
123  //------------------------------------------------------------------------
125  //------------------------------------------------------------------------
126  std::ostream & Write(std::ostream & os) const;
127 
128  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
132  ssize_t Read(int fd);
133 
134  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  ssize_t Write(int fd) const;
139 
140  //------------------------------------------------------------------------
143  //------------------------------------------------------------------------
144  size_t Read(FILE *f);
145 
146  //------------------------------------------------------------------------
149  //------------------------------------------------------------------------
150  size_t Write(FILE *f) const;
151 
152  //------------------------------------------------------------------------
155  //------------------------------------------------------------------------
156  int Read(gzFile gzf);
157 
158  //------------------------------------------------------------------------
161  //------------------------------------------------------------------------
162  int Write(gzFile gzf) const;
163 
164  //------------------------------------------------------------------------
167  //------------------------------------------------------------------------
168  int BZRead(BZFILE *bzf);
169 
170  //------------------------------------------------------------------------
173  //------------------------------------------------------------------------
174  int BZWrite(BZFILE *bzf) const;
175 
176  //------------------------------------------------------------------------
179  //------------------------------------------------------------------------
180  uint32_t StreamedLength() const;
181 
182  //------------------------------------------------------------------------
184  //------------------------------------------------------------------------
185  friend std::ostream &
186  operator << (std::ostream & os, const MplsLabel & label);
187 
188  //------------------------------------------------------------------------
190  //------------------------------------------------------------------------
191  friend std::istream &
192  operator >> (std::istream & is, MplsLabel & label);
193 
194  protected:
195  uint32_t _data;
196  };
197 
198 } // namespace Dwm
199 
200 #endif // _DWMMPLSLABEL_HH_
201 
202 //---------------------------- emacs settings -----------------------------
203 // Local Variables:
204 // mode: C++/la
205 // tab-width: 2
206 // indent-tabs-mode: nil
207 // c-basic-offset: 2
208 // End:
209 //-------------------------------------------------------------------------
uint32_t Label() const
Returns the 20-bit label portion of the label.
friend std::istream & operator>>(std::istream &is, MplsLabel &label)
Reads from an istream in &#39;label:exp:s:ttl&#39; format.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
Dwm::Writable pure virtual class definition.
Dwm::BZ2Readable pure virtual class definition.
friend std::ostream & operator<<(std::ostream &os, const MplsLabel &label)
Prints to an ostream in &#39;label:exp:s:ttl&#39; format.
Dwm::GZReadable pure virtual class definition.
Dwm::Readable pure virtual class definition.
std::ostream & Write(std::ostream &os) const
Writes the MPLS label to an ostream. Returns the ostream.
Encapsulates an MPLS label.
Definition: DwmMplsLabel.hh:57
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmBZ2Readable.hh:57
uint8_t Ttl() const
Returns the TTL portion of the label.
MplsLabel()
Constructor. Sets all label bits to 0.
int BZWrite(BZFILE *bzf) const
Writes the MPLS lable to the given BZFILE bzf.
Dwm::BZ2Writable pure virtual class definition.
Definition: DwmBZ2IO.hh:67
bool S() const
Returns true if the S (bottom-of-stack) bit is set.
bool operator==(const MplsLabel &label) const
operator ==
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
std::istream & Read(std::istream &is)
Reads the MPLS label from an istream. Returns the istream.
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
int BZRead(BZFILE *bzf)
Reads the MPLS label from the given BZFILE bzf.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmBZ2Writable.hh:57
Dwm::GZWritable pure virtual class definition.
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
uint32_t StreamedLength() const
Returns the number of bytes that should be written if we call one of the Write() members.
uint8_t Exp() const
Returns the 3-bit exp portion of the label.