blob: acf66dbb3e5c0b3eb5c9bee69ba69054d67aa451 [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 Guptabc886292017-07-25 18:29:57 +053029 Interfaces(bus, objPath.c_str(), true),
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053030 EthernetInterface(bus, objPath, dhcpEnabled, parent, false),
31 parentInterface(intf)
32{
33 id(vlanID);
34 VlanIface::interfaceName(EthernetInterface::interfaceName());
Ratan Gupta6e8df632017-08-13 09:41:58 +053035 mACAddress(parentInterface.mACAddress());
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053036
Ratan Guptabc886292017-07-25 18:29:57 +053037 Interfaces::emit_object_added();
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053038}
39
40void VlanInterface::writeDeviceFile()
41{
42 using namespace std::string_literals;
43 fs::path confPath = manager.getConfDir();
44 std::string fileName = EthernetInterface::interfaceName() + ".netdev"s;
45 confPath /= fileName;
46 std::fstream stream;
47 try
48 {
49 stream.open(confPath.c_str(), std::fstream::out);
50 }
51 catch (std::ios_base::failure& e)
52 {
53 log<level::ERR>("Unable to open the VLAN device file",
54 entry("FILE=%s", confPath.c_str()),
55 entry("ERROR=%s", e.what()));
56 elog<InternalFailure>();
57
58 }
59
60 stream << "[" << "NetDev" << "]\n";
61 stream << "Name=" << EthernetInterface::interfaceName() << "\n";
62 stream << "Kind=vlan" << "\n";
63 stream << "[VLAN]" << "\n";
64 stream << "Id=" << id() << "\n";
65 stream.close();
66}
67
Ratan Guptabc886292017-07-25 18:29:57 +053068void VlanInterface::delete_()
69{
70 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
71}
72
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053073}//namespace network
74}//namespace phosphor