2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 #include "vom/types.hpp"
25 rc_t::rc_t(int v, const std::string s)
26 : enum_base<rc_t>(v, s)
34 rc_t::from_vpp_retval(int32_t rv)
40 // interface laready exists
44 return (rc_t::INVALID);
47 const rc_t rc_t::UNSET(0, "un-set");
48 const rc_t rc_t::NOOP(1, "no-op");
49 const rc_t rc_t::OK(2, "ok");
50 const rc_t rc_t::INPROGRESS(3, "in-progess");
51 const rc_t rc_t::INVALID(4, "invalid");
52 const rc_t rc_t::TIMEOUT(5, "timeout");
54 const handle_t handle_t::INVALID(~0);
56 handle_t::handle_t(int value)
67 handle_t::to_string() const
69 return (std::to_string(m_value));
73 handle_t::operator==(const handle_t& other) const
75 return (m_value == other.m_value);
79 handle_t::operator!=(const handle_t& other) const
81 return (!(*this == other));
85 handle_t::operator<(const handle_t& other) const
87 return (m_value < other.m_value);
91 handle_t::value() const
97 operator<<(std::ostream& os, const handle_t& h)
104 mac_address_t::mac_address_t(uint8_t b[6])
106 std::copy(b, b + 6, std::begin(bytes));
109 mac_address_t::mac_address_t(std::initializer_list<uint8_t> i)
111 std::copy(i.begin(), i.end(), std::begin(bytes));
114 const mac_address_t mac_address_t::ONE({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff });
116 const mac_address_t mac_address_t::ZERO({ 0x0 });
119 mac_address_t::to_bytes(uint8_t* array, uint8_t len) const
121 for (int i = 0; i < 6 && i < len; i++) {
127 mac_address_t::to_string() const
129 std::ostringstream s;
135 for (auto byte : bytes) {
140 s << std::setw(2) << static_cast<unsigned int>(byte);
148 mac_address_t::operator==(const mac_address_t& mac) const
150 return (bytes == mac.bytes);
153 mac_address_t::operator<(const mac_address_t& m) const
155 return (bytes < m.bytes);
159 operator<<(std::ostream& os, const mac_address_t& mac)
161 os << mac.to_string();
166 l2_address_t::l2_address_t(const uint8_t b[8], uint8_t n_bytes)
169 std::copy_n(b, n_bytes, std::begin(bytes));
172 l2_address_t::l2_address_t(std::initializer_list<uint8_t> i)
177 l2_address_t::l2_address_t(const mac_address_t& mac)
180 std::copy(begin(mac.bytes), std::end(mac.bytes), std::begin(bytes));
183 const l2_address_t l2_address_t::ONE({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
186 const l2_address_t l2_address_t::ZERO({ 0x0 });
189 l2_address_t::to_bytes(uint8_t* array, uint8_t len) const
191 for (uint8_t i = 0; i < bytes.size() && i < len; i++) {
197 l2_address_t::to_mac() const
199 mac_address_t mac({});
201 std::copy_n(bytes.begin(), mac.bytes.size(), mac.bytes.begin());
207 l2_address_t::to_string() const
209 std::ostringstream s;
214 for (auto byte : bytes) {
219 s << std::setw(2) << static_cast<unsigned int>(byte);
226 l2_address_t::operator==(const l2_address_t& l2) const
228 return (bytes == l2.bytes);
232 l2_address_t::operator!=(const l2_address_t& l2) const
234 return (bytes != l2.bytes);
238 operator<<(std::ostream& os, const l2_address_t& l2)
240 os << l2.to_string();
245 const direction_t direction_t::INPUT(1, "input");
246 const direction_t direction_t::OUTPUT(0, "output");
248 direction_t::direction_t(int v, const std::string s)
255 * fd.io coding-style-patch-verification: ON
258 * eval: (c-set-style "mozilla")