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(uint64_t address)
108 std::memcpy(mac, &address, 6);
109 for (int i = 0; i < 6; i++) {
110 bytes[i] = mac[5 - i];
114 mac_address_t::mac_address_t(uint8_t b[6])
116 std::copy(b, b + 6, std::begin(bytes));
119 mac_address_t::mac_address_t(std::initializer_list<uint8_t> i)
121 std::copy(i.begin(), i.end(), std::begin(bytes));
124 const mac_address_t mac_address_t::ONE({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff });
126 const mac_address_t mac_address_t::ZERO({ 0x0 });
129 mac_address_t::to_bytes(uint8_t* array, uint8_t len) const
131 for (int i = 0; i < 6 && i < len; i++) {
137 mac_address_t::to_u64() const
140 uint8_t* b = reinterpret_cast<uint8_t*>(&mac6);
142 // whack hack. the vapi will byte swap.
154 mac_address_t::to_string() const
156 std::ostringstream s;
162 for (auto byte : bytes) {
167 s << std::setw(2) << static_cast<unsigned int>(byte);
175 mac_address_t::operator==(const mac_address_t& mac) const
177 return (bytes == mac.bytes);
180 mac_address_t::operator<(const mac_address_t& m) const
182 return (bytes < m.bytes);
186 operator<<(std::ostream& os, const mac_address_t& mac)
188 os << mac.to_string();
193 l2_address_t::l2_address_t(const uint8_t b[8], uint8_t n_bytes)
196 std::copy_n(b, n_bytes, std::begin(bytes));
199 l2_address_t::l2_address_t(std::initializer_list<uint8_t> i)
204 l2_address_t::l2_address_t(const mac_address_t& mac)
207 std::copy(begin(mac.bytes), std::end(mac.bytes), std::begin(bytes));
210 const l2_address_t l2_address_t::ONE({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
213 const l2_address_t l2_address_t::ZERO({ 0x0 });
216 l2_address_t::to_bytes(uint8_t* array, uint8_t len) const
218 for (uint8_t i = 0; i < bytes.size() && i < len; i++) {
224 l2_address_t::to_mac() const
226 mac_address_t mac({});
228 std::copy_n(bytes.begin(), mac.bytes.size(), mac.bytes.begin());
234 l2_address_t::to_string() const
236 std::ostringstream s;
241 for (auto byte : bytes) {
246 s << std::setw(2) << static_cast<unsigned int>(byte);
253 l2_address_t::operator==(const l2_address_t& l2) const
255 return (bytes == l2.bytes);
259 l2_address_t::operator!=(const l2_address_t& l2) const
261 return (bytes != l2.bytes);
265 operator<<(std::ostream& os, const l2_address_t& l2)
267 os << l2.to_string();
272 const direction_t direction_t::INPUT(1, "input");
273 const direction_t direction_t::OUTPUT(0, "output");
275 direction_t::direction_t(int v, const std::string s)
282 * fd.io coding-style-patch-verification: ON
285 * eval: (c-set-style "mozilla")