Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / msg / async / dpdk / ethernet.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
2 /*
3  * This file is open source software, licensed to you under the terms
4  * of the Apache License, Version 2.0 (the "License").  See the NOTICE file
5  * distributed with this work for additional information regarding copyright
6  * ownership.  You may not use this file except in compliance with the License.
7  *
8  * You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 /*
20  * Copyright (C) 2014 Cloudius Systems, Ltd.
21  */
22
23 #ifndef CEPH_MSG_ETHERNET_H_
24 #define CEPH_MSG_ETHERNET_H_
25
26 #include <array>
27 #include <sstream>
28
29 #include "include/assert.h"
30 #include "byteorder.h"
31
32 struct ethernet_address {
33   ethernet_address() {}
34
35   ethernet_address(const uint8_t *eaddr) {
36     std::copy(eaddr, eaddr + 6, mac.begin());
37   }
38
39   ethernet_address(std::initializer_list<uint8_t> eaddr) {
40     assert(eaddr.size() == mac.size());
41     std::copy(eaddr.begin(), eaddr.end(), mac.begin());
42   }
43
44   ethernet_address ntoh() {
45     return *this;
46   }
47   ethernet_address hton() {
48     return *this;
49   }
50   std::array<uint8_t, 6> mac;
51 } __attribute__((packed));
52
53 inline bool operator==(const ethernet_address& a, const ethernet_address& b) {
54   return a.mac == b.mac;
55 }
56 std::ostream& operator<<(std::ostream& os, const ethernet_address& ea);
57
58 struct ethernet {
59   using address = ethernet_address;
60   static address broadcast_address() {
61       return  {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
62   }
63   static constexpr uint16_t arp_hardware_type() { return 1; }
64 };
65
66 struct eth_hdr {
67   ethernet_address dst_mac;
68   ethernet_address src_mac;
69   uint16_t eth_proto;
70   eth_hdr hton() {
71     eth_hdr hdr = *this;
72     hdr.eth_proto = ::hton(eth_proto);
73     return hdr;
74   }
75   eth_hdr ntoh() {
76     eth_hdr hdr = *this;
77     hdr.eth_proto = ::ntoh(eth_proto);
78     return hdr;
79   }
80 } __attribute__((packed));
81
82 ethernet_address parse_ethernet_address(std::string addr);
83
84 #endif /* CEPH_MSG_ETHERNET_H_ */