/
tunnel_encap_type.cc
81 lines (71 loc) · 2.96 KB
/
tunnel_encap_type.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <map>
#include "net/tunnel_encap_type.h"
#include <boost/assign/list_of.hpp>
using std::map;
using std::string;
TunnelEncapType::TunnelEncapType() {
}
static const map<string, TunnelEncapType::Encap>
fromString = boost::assign::map_list_of
("unspecified", TunnelEncapType::UNSPEC)
("gre", TunnelEncapType::GRE)
("vxlan", TunnelEncapType::VXLAN)
("nvgre", TunnelEncapType::NVGRE)
("mpls", TunnelEncapType::MPLS)
("vxlan-gpe", TunnelEncapType::VXLAN_GPE)
("udp", TunnelEncapType::MPLS_O_UDP)
("udp-contrail", TunnelEncapType::MPLS_O_UDP_CONTRAIL)
("vxlan-contrail", TunnelEncapType::VXLAN_CONTRAIL);
static const map<TunnelEncapType::Encap, string>
toString = boost::assign::map_list_of
(TunnelEncapType::UNSPEC, "unspecified")
(TunnelEncapType::GRE, "gre")
(TunnelEncapType::VXLAN, "vxlan")
(TunnelEncapType::NVGRE, "nvgre")
(TunnelEncapType::MPLS, "mpls")
(TunnelEncapType::MPLS_O_GRE, "mpls-o-gre")
(TunnelEncapType::VXLAN_GPE, "vxlan-gpe")
(TunnelEncapType::MPLS_O_UDP, "udp")
(TunnelEncapType::MPLS_O_UDP_CONTRAIL, "udp-contrail")
(TunnelEncapType::VXLAN_CONTRAIL, "vxlan-contrail");
static const map<TunnelEncapType::Encap, string>
toXmppString = boost::assign::map_list_of
(TunnelEncapType::UNSPEC, "unspecified")
(TunnelEncapType::GRE, "gre")
(TunnelEncapType::VXLAN, "vxlan")
(TunnelEncapType::NVGRE, "nvgre")
(TunnelEncapType::MPLS, "mpls")
(TunnelEncapType::MPLS_O_GRE, "gre")
(TunnelEncapType::VXLAN_GPE, "vxlan-gpe")
(TunnelEncapType::MPLS_O_UDP, "udp")
(TunnelEncapType::MPLS_O_UDP_CONTRAIL, "udp")
(TunnelEncapType::VXLAN_CONTRAIL, "vxlan");
bool TunnelEncapType::TunnelEncapIsValid(uint16_t value) {
TunnelEncapType::Encap encap = static_cast<TunnelEncapType::Encap>(value);
map<TunnelEncapType::Encap, string>::const_iterator it =
toXmppString.find(encap);
return (it == toXmppString.end() ? false : true);
}
TunnelEncapType::Encap TunnelEncapType::TunnelEncapFromString(
const string &encap) {
map<string, TunnelEncapType::Encap>::const_iterator it =
fromString.find(encap);
return (it == fromString.end() ? TunnelEncapType::UNSPEC : it->second);
}
const string &TunnelEncapType::TunnelEncapToString(
TunnelEncapType::Encap encap) {
static string unspecified("unspecified");
map<TunnelEncapType::Encap, string>::const_iterator it =
toString.find(encap);
return (it == toString.end() ? unspecified : it->second);
}
const string &TunnelEncapType::TunnelEncapToXmppString(
TunnelEncapType::Encap encap) {
static string unspecified("unspecified");
map<TunnelEncapType::Encap, string>::const_iterator it =
toXmppString.find(encap);
return (it == toXmppString.end() ? unspecified : it->second);
}