blob: 8f7c5ce034d27f2ebb483df3611a0111dee68c4c [file] [log] [blame]
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05301#include "config.h"
2#include "ethernet_interface.hpp"
3#include "vlan_interface.hpp"
4#include "network_manager.hpp"
5
6#include <phosphor-logging/log.hpp>
7#include "xyz/openbmc_project/Common/error.hpp"
8#include <phosphor-logging/elog-errors.hpp>
9
10#include <string>
11#include <algorithm>
12#include <fstream>
13#include <experimental/filesystem>
14
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