blob: e7854de2f045843757551e36137bf0733e77d39d [file] [log] [blame]
Patrick Venture189d44e2018-07-09 12:30:59 -07001#include "vlan_interface.hpp"
2
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05303#include "config.h"
4#include "ethernet_interface.hpp"
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05305#include "network_manager.hpp"
6
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05307#include <algorithm>
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05308#include <experimental/filesystem>
Patrick Venture189d44e2018-07-09 12:30:59 -07009#include <fstream>
10#include <phosphor-logging/elog-errors.hpp>
11#include <phosphor-logging/log.hpp>
12#include <string>
13#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053014
15namespace phosphor
16{
17namespace network
18{
19
20using namespace phosphor::logging;
21using namespace sdbusplus::xyz::openbmc_project::Common::Error;
22
23VlanInterface::VlanInterface(sdbusplus::bus::bus& bus,
24 const std::string& objPath,
25 bool dhcpEnabled,
26 uint32_t vlanID,
27 EthernetInterface& intf,
28 Manager& parent ) :
Ratan Gupta26e87a02017-08-18 01:08:40 +053029 VlanIface(bus,objPath.c_str()),
30 DeleteIface(bus,objPath.c_str()),
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053031 EthernetInterface(bus, objPath, dhcpEnabled, parent, false),
32 parentInterface(intf)
33{
34 id(vlanID);
35 VlanIface::interfaceName(EthernetInterface::interfaceName());
Ratan Guptabd303b12017-08-18 17:10:07 +053036 MacAddressIntf::mACAddress(parentInterface.mACAddress());
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053037
Ratan Gupta26e87a02017-08-18 01:08:40 +053038 emit_object_added();
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053039}
40
41void VlanInterface::writeDeviceFile()
42{
43 using namespace std::string_literals;
44 fs::path confPath = manager.getConfDir();
45 std::string fileName = EthernetInterface::interfaceName() + ".netdev"s;
46 confPath /= fileName;
47 std::fstream stream;
48 try
49 {
50 stream.open(confPath.c_str(), std::fstream::out);
51 }
52 catch (std::ios_base::failure& e)
53 {
54 log<level::ERR>("Unable to open the VLAN device file",
55 entry("FILE=%s", confPath.c_str()),
56 entry("ERROR=%s", e.what()));
57 elog<InternalFailure>();
58
59 }
60
61 stream << "[" << "NetDev" << "]\n";
62 stream << "Name=" << EthernetInterface::interfaceName() << "\n";
63 stream << "Kind=vlan" << "\n";
64 stream << "[VLAN]" << "\n";
65 stream << "Id=" << id() << "\n";
66 stream.close();
67}
68
Ratan Guptabc886292017-07-25 18:29:57 +053069void VlanInterface::delete_()
70{
71 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
72}
73
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053074}//namespace network
75}//namespace phosphor