blob: 9f921988fde9a3a8758330b42f35020efbb63ab8 [file] [log] [blame]
Patrick Venture189d44e2018-07-09 12:30:59 -07001#include "vlan_interface.hpp"
2
William A. Kennington III9c9f1b72022-08-18 17:55:29 -07003#include "config_parser.hpp"
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05304#include "ethernet_interface.hpp"
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05305#include "network_manager.hpp"
6
Patrick Venture189d44e2018-07-09 12:30:59 -07007#include <phosphor-logging/elog-errors.hpp>
8#include <phosphor-logging/log.hpp>
9#include <string>
10#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053011
12namespace phosphor
13{
14namespace network
15{
16
17using namespace phosphor::logging;
18using namespace sdbusplus::xyz::openbmc_project::Common::Error;
19
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -070020VlanInterface::VlanInterface(sdbusplus::bus_t& bus,
21 stdplus::const_zstring objPath,
William A. Kennington III0caf2212022-08-18 18:15:51 -070022 const config::Parser& config, bool nicEnabled,
23 uint32_t vlanID, EthernetInterface& intf,
24 Manager& parent) :
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053025 VlanIface(bus, objPath.c_str()),
26 DeleteIface(bus, objPath.c_str()),
William A. Kennington III0caf2212022-08-18 18:15:51 -070027 EthernetInterface(bus, objPath, config, parent, true, nicEnabled),
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053028 parentInterface(intf)
29{
30 id(vlanID);
Patrick Williams6aef7692021-05-01 06:39:41 -050031 MacAddressIntf::macAddress(parentInterface.macAddress());
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053032
33 emit_object_added();
34}
35
Patrick Williams6aef7692021-05-01 06:39:41 -050036std::string VlanInterface::macAddress(std::string)
William A. Kennington IIIa2145bf2019-04-19 13:15:56 -070037{
38 log<level::ERR>("Tried to set MAC address on VLAN");
39 elog<InternalFailure>();
40}
41
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053042void VlanInterface::writeDeviceFile()
43{
William A. Kennington III9c9f1b72022-08-18 17:55:29 -070044 config::Parser config;
45 auto& netdev = config.map["NetDev"].emplace_back();
46 netdev["Name"].emplace_back(EthernetInterface::interfaceName());
47 netdev["Kind"].emplace_back("vlan");
48 config.map["VLAN"].emplace_back()["Id"].emplace_back(std::to_string(id()));
49 config.writeFile(config::pathForIntfDev(
50 manager.getConfDir(), EthernetInterface::interfaceName()));
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053051}
52
Ratan Guptabc886292017-07-25 18:29:57 +053053void VlanInterface::delete_()
54{
55 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
56}
57
Gunnar Mills57d9c502018-09-14 14:42:34 -050058} // namespace network
59} // namespace phosphor