blob: cb086c7f191f959a8acce9f5a02294b6a4d3f870 [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"
William A. Kennington IIIfd862be2022-10-09 18:40:55 -07006#include "system_queries.hpp"
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05307
Patrick Venture189d44e2018-07-09 12:30:59 -07008#include <phosphor-logging/elog-errors.hpp>
9#include <phosphor-logging/log.hpp>
10#include <string>
11#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053012
13namespace phosphor
14{
15namespace network
16{
17
18using namespace phosphor::logging;
19using namespace sdbusplus::xyz::openbmc_project::Common::Error;
20
William A. Kennington IIId298f932022-10-17 14:31:38 -070021VlanInterface::VlanInterface(sdbusplus::bus_t& bus, Manager& manager,
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070022 const system::InterfaceInfo& info,
William A. Kennington IIId298f932022-10-17 14:31:38 -070023 std::string_view objRoot,
24 const config::Parser& config, uint16_t vlanID,
25 EthernetInterface& parent, bool emitSignal,
26 std::optional<bool> enabled) :
27 EthernetInterface(bus, manager, info, objRoot, config, emitSignal, enabled),
28 DeleteIface(bus, objPath.c_str()), VlanIface(bus, objPath.c_str()),
29 parentInterface(parent)
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053030{
31 id(vlanID);
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053032 emit_object_added();
33}
34
Patrick Williams6aef7692021-05-01 06:39:41 -050035std::string VlanInterface::macAddress(std::string)
William A. Kennington IIIa2145bf2019-04-19 13:15:56 -070036{
37 log<level::ERR>("Tried to set MAC address on VLAN");
38 elog<InternalFailure>();
39}
40
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053041void VlanInterface::writeDeviceFile()
42{
William A. Kennington III9c9f1b72022-08-18 17:55:29 -070043 config::Parser config;
44 auto& netdev = config.map["NetDev"].emplace_back();
45 netdev["Name"].emplace_back(EthernetInterface::interfaceName());
46 netdev["Kind"].emplace_back("vlan");
47 config.map["VLAN"].emplace_back()["Id"].emplace_back(std::to_string(id()));
48 config.writeFile(config::pathForIntfDev(
49 manager.getConfDir(), EthernetInterface::interfaceName()));
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053050}
51
Ratan Guptabc886292017-07-25 18:29:57 +053052void VlanInterface::delete_()
53{
54 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
55}
56
Gunnar Mills57d9c502018-09-14 14:42:34 -050057} // namespace network
58} // namespace phosphor