blob: 1ea6a17582511598640ef53f68ae465c2a3a1343 [file] [log] [blame]
Gunnar Mills57d9c502018-09-14 14:42:34 -05001#include "config.h"
2
Patrick Venture189d44e2018-07-09 12:30:59 -07003#include "vlan_interface.hpp"
4
William A. Kennington III9c9f1b72022-08-18 17:55:29 -07005#include "config_parser.hpp"
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05306#include "ethernet_interface.hpp"
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05307#include "network_manager.hpp"
8
Patrick Venture189d44e2018-07-09 12:30:59 -07009#include <phosphor-logging/elog-errors.hpp>
10#include <phosphor-logging/log.hpp>
11#include <string>
12#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053013
14namespace phosphor
15{
16namespace network
17{
18
19using namespace phosphor::logging;
20using namespace sdbusplus::xyz::openbmc_project::Common::Error;
21
Patrick Williamsc38b0712022-07-22 19:26:54 -050022VlanInterface::VlanInterface(sdbusplus::bus_t& bus, const std::string& objPath,
William A. Kennington IIIa520a392022-08-08 12:17:34 -070023 const config::Parser& config, DHCPConf dhcpEnabled,
24 bool nicEnabled, uint32_t vlanID,
25 EthernetInterface& intf, Manager& parent) :
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053026 VlanIface(bus, objPath.c_str()),
27 DeleteIface(bus, objPath.c_str()),
William A. Kennington IIIa520a392022-08-08 12:17:34 -070028 EthernetInterface(bus, objPath, config, dhcpEnabled, parent, true,
29 nicEnabled),
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053030 parentInterface(intf)
31{
32 id(vlanID);
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053033 VlanIface::interfaceName(EthernetInterface::interfaceName());
Patrick Williams6aef7692021-05-01 06:39:41 -050034 MacAddressIntf::macAddress(parentInterface.macAddress());
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053035
36 emit_object_added();
37}
38
Patrick Williams6aef7692021-05-01 06:39:41 -050039std::string VlanInterface::macAddress(std::string)
William A. Kennington IIIa2145bf2019-04-19 13:15:56 -070040{
41 log<level::ERR>("Tried to set MAC address on VLAN");
42 elog<InternalFailure>();
43}
44
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053045void VlanInterface::writeDeviceFile()
46{
William A. Kennington III9c9f1b72022-08-18 17:55:29 -070047 config::Parser config;
48 auto& netdev = config.map["NetDev"].emplace_back();
49 netdev["Name"].emplace_back(EthernetInterface::interfaceName());
50 netdev["Kind"].emplace_back("vlan");
51 config.map["VLAN"].emplace_back()["Id"].emplace_back(std::to_string(id()));
52 config.writeFile(config::pathForIntfDev(
53 manager.getConfDir(), EthernetInterface::interfaceName()));
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053054}
55
Ratan Guptabc886292017-07-25 18:29:57 +053056void VlanInterface::delete_()
57{
58 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
59}
60
Gunnar Mills57d9c502018-09-14 14:42:34 -050061} // namespace network
62} // namespace phosphor