blob: f4224d4fb8d808d5e71fa7c99e006a980fa375a6 [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 ) :
29 VlanIntfObject(bus, objPath.c_str(), true),
30 EthernetInterface(bus, objPath, dhcpEnabled, parent, false),
31 parentInterface(intf)
32{
33 id(vlanID);
34 VlanIface::interfaceName(EthernetInterface::interfaceName());
35
36 VlanIntfObject::emit_object_added();
37}
38
39void VlanInterface::writeDeviceFile()
40{
41 using namespace std::string_literals;
42 fs::path confPath = manager.getConfDir();
43 std::string fileName = EthernetInterface::interfaceName() + ".netdev"s;
44 confPath /= fileName;
45 std::fstream stream;
46 try
47 {
48 stream.open(confPath.c_str(), std::fstream::out);
49 }
50 catch (std::ios_base::failure& e)
51 {
52 log<level::ERR>("Unable to open the VLAN device file",
53 entry("FILE=%s", confPath.c_str()),
54 entry("ERROR=%s", e.what()));
55 elog<InternalFailure>();
56
57 }
58
59 stream << "[" << "NetDev" << "]\n";
60 stream << "Name=" << EthernetInterface::interfaceName() << "\n";
61 stream << "Kind=vlan" << "\n";
62 stream << "[VLAN]" << "\n";
63 stream << "Id=" << id() << "\n";
64 stream.close();
65}
66
67}//namespace network
68}//namespace phosphor