blob: 0d7879c6768b6184cbef08e9f0e562a68a18d392 [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 IIId298f932022-10-17 14:31:38 -070020VlanInterface::VlanInterface(sdbusplus::bus_t& bus, Manager& manager,
21 const InterfaceInfo& info,
22 std::string_view objRoot,
23 const config::Parser& config, uint16_t vlanID,
24 EthernetInterface& parent, bool emitSignal,
25 std::optional<bool> enabled) :
26 EthernetInterface(bus, manager, info, objRoot, config, emitSignal, enabled),
27 DeleteIface(bus, objPath.c_str()), VlanIface(bus, objPath.c_str()),
28 parentInterface(parent)
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053029{
30 id(vlanID);
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053031 emit_object_added();
32}
33
Patrick Williams6aef7692021-05-01 06:39:41 -050034std::string VlanInterface::macAddress(std::string)
William A. Kennington IIIa2145bf2019-04-19 13:15:56 -070035{
36 log<level::ERR>("Tried to set MAC address on VLAN");
37 elog<InternalFailure>();
38}
39
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053040void VlanInterface::writeDeviceFile()
41{
William A. Kennington III9c9f1b72022-08-18 17:55:29 -070042 config::Parser config;
43 auto& netdev = config.map["NetDev"].emplace_back();
44 netdev["Name"].emplace_back(EthernetInterface::interfaceName());
45 netdev["Kind"].emplace_back("vlan");
46 config.map["VLAN"].emplace_back()["Id"].emplace_back(std::to_string(id()));
47 config.writeFile(config::pathForIntfDev(
48 manager.getConfDir(), EthernetInterface::interfaceName()));
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053049}
50
Ratan Guptabc886292017-07-25 18:29:57 +053051void VlanInterface::delete_()
52{
53 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
54}
55
Gunnar Mills57d9c502018-09-14 14:42:34 -050056} // namespace network
57} // namespace phosphor