OpenSDN source code
tunnel_encap.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
7 
8 
9 #include <algorithm>
10 #include <sstream>
11 
12 
13 using std::copy;
14 using std::fill;
15 using std::string;
16 
17 TunnelEncap::TunnelEncap(string encap) {
18  fill(data_.begin(), data_.end(), 0);
20  if (id == TunnelEncapType::UNSPEC) return;
21  data_[0] = 0x03;
22  data_[1] = 0x0C;
23  // Reserved
24  put_value(&data_[2], 4, 0);
25  put_value(&data_[6], 2, id);
26 }
27 
29  fill(data_.begin(), data_.end(), 0);
30  data_[0] = 0x03;
31  data_[1] = 0x0C;
32  // Reserved
33  put_value(&data_[2], 4, 0);
34  put_value(&data_[6], 2, tunnel_encap);
35 }
36 
38  copy(data.begin(), data.end(), data_.begin());
39 }
40 
42  if (data_[0] != 0x03 || data_[1] != 0x0c)
44  uint16_t value = get_value(&data_[6], 2);
46  return static_cast<TunnelEncapType::Encap>(value);
47  } else {
49  }
50 }
51 
53  string str("encapsulation:");
55  return str;
56 }
57 
60 }
static const std::string & TunnelEncapToString(TunnelEncapType::Encap encap)
static bool TunnelEncapIsValid(uint16_t value)
static TunnelEncapType::Encap TunnelEncapFromString(const std::string &encap)
static const std::string & TunnelEncapToXmppString(TunnelEncapType::Encap encap)
boost::array< uint8_t, kSize > bytes_type
Definition: tunnel_encap.h:21
TunnelEncap(TunnelEncapType::Encap encap)
Definition: tunnel_encap.cc:28
std::string ToString()
Definition: tunnel_encap.cc:52
std::string ToXmppString()
Definition: tunnel_encap.cc:58
TunnelEncapType::Encap tunnel_encap() const
Definition: tunnel_encap.cc:41
bytes_type data_
Definition: tunnel_encap.h:40
static void put_value(uint8_t *data, int size, uint64_t value)
Definition: parse_object.h:56
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:40