Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 1 | #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 | |
| 15 | namespace phosphor |
| 16 | { |
| 17 | namespace network |
| 18 | { |
| 19 | |
| 20 | using namespace phosphor::logging; |
| 21 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 22 | |
| 23 | VlanInterface::VlanInterface(sdbusplus::bus::bus& bus, |
| 24 | const std::string& objPath, |
| 25 | bool dhcpEnabled, |
| 26 | uint32_t vlanID, |
| 27 | EthernetInterface& intf, |
| 28 | Manager& parent ) : |
Ratan Gupta | 26e87a0 | 2017-08-18 01:08:40 +0530 | [diff] [blame] | 29 | VlanIface(bus,objPath.c_str()), |
| 30 | DeleteIface(bus,objPath.c_str()), |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 31 | EthernetInterface(bus, objPath, dhcpEnabled, parent, false), |
| 32 | parentInterface(intf) |
| 33 | { |
| 34 | id(vlanID); |
| 35 | VlanIface::interfaceName(EthernetInterface::interfaceName()); |
Ratan Gupta | bd303b1 | 2017-08-18 17:10:07 +0530 | [diff] [blame^] | 36 | MacAddressIntf::mACAddress(parentInterface.mACAddress()); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 37 | |
Ratan Gupta | 26e87a0 | 2017-08-18 01:08:40 +0530 | [diff] [blame] | 38 | emit_object_added(); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void 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 Gupta | bc88629 | 2017-07-25 18:29:57 +0530 | [diff] [blame] | 69 | void VlanInterface::delete_() |
| 70 | { |
| 71 | parentInterface.deleteVLANObject(EthernetInterface::interfaceName()); |
| 72 | } |
| 73 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 74 | }//namespace network |
| 75 | }//namespace phosphor |