Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
network-config.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License version 2.1 as published by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
24 #ifndef LXCPP_NETWORK_CONFIG_HPP
25 #define LXCPP_NETWORK_CONFIG_HPP
26 
27 #include "config.hpp"
28 #include "cargo/fields.hpp"
29 #include "lxcpp/network.hpp"
30 #include "lxcpp/exception.hpp"
31 
32 #include <vector>
33 #include <string>
34 
35 #include <string.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38 
39 namespace lxcpp {
40 
45 public:
46  NetworkInterfaceConfig() = default; // default constructor required by visitor
47 
48  NetworkInterfaceConfig(const std::string& hostif,
49  const std::string& zoneif,
50  InterfaceType type,
51  const std::vector<InetAddr>& addrs,
52  MacVLanMode mode) :
53  mHostIf(hostif),
54  mZoneIf(zoneif),
55  mType(static_cast<int>(type)),
56  mMode(static_cast<int>(mode)),
57  mMtu(0),
58  mMacAddress(),
59  mTxLength(0),
60  mIpAddrList(addrs)
61  {
62  }
63 
64  const std::string& getHostIf() const;
65 
66  const std::string& getZoneIf() const;
67 
68  InterfaceType getType() const;
69 
70  MacVLanMode getMode() const;
71 
72  void setMTU(int mtu);
73  int getMTU() const;
74 
75  void setMACAddress(const std::string& mac);
76  const std::string& getMACAddress() const;
77 
78  void setTxLength(int txlen);
79  int getTxLength() const;
80 
81  const std::vector<InetAddr>& getAddrList() const;
82 
83  void addInetAddr(const InetAddr& addr);
84 
86  (
87  mHostIf,
88  mZoneIf,
89  mType,
90  mMode,
92  )
93 
94 private:
95  std::string mHostIf;
96  std::string mZoneIf;
97  int mType;
98  int mMode;
99 
100  /*
101  * interface parameters which can be set after interface is created
102  * MTU (Maximum Transmit Unit) is maximum length of link level packet in TCP stream
103  * MAC address is also called hardware card address
104  * TXQueue is transmit queue length
105  *
106  * I think most useful would be possibility to set MAC address, other have their
107  * well working defaults but can be tuned to make faster networking (especially locally)
108  */
109  int mMtu;
110  std::string mMacAddress;
112 
113  std::vector<InetAddr> mIpAddrList;
114 };
115 
120 public:
125  void addInterfaceConfig(const std::string& hostif,
126  const std::string& zoneif,
127  InterfaceType type,
128  const std::vector<InetAddr>& addrs = std::vector<InetAddr>(),
130  void addInetConfig(const std::string& ifname, const InetAddr& addr);
131 
132  const std::vector<NetworkInterfaceConfig>& getInterfaces() const { return mInterfaces; }
133  const NetworkInterfaceConfig& getInterface(int i) const { return mInterfaces.at(i); }
134 
136  mInterfaces
137  )
138 
139 private:
140  std::vector<NetworkInterfaceConfig> mInterfaces;
141 };
142 
143 } //namespace lxcpp
144 
145 #endif // LXCPP_NETWORK_CONFIG_HPP
void addInetConfig(const std::string &ifname, const InetAddr &addr)
Definition: network-config.cpp:117
CARGO_REGISTER(mHostIf, mZoneIf, mType, mMode, mIpAddrList) private std::string mZoneIf
Definition: network-config.hpp:86
int getTxLength() const
Definition: network-config.cpp:77
const std::vector< InetAddr > & getAddrList() const
Definition: network-config.cpp:82
const std::string & getZoneIf() const
Definition: network-config.cpp:37
Network interface configuration.
Definition: network-config.hpp:44
int mMtu
Definition: network-config.hpp:109
void addInterfaceConfig(const std::string &hostif, const std::string &zoneif, InterfaceType type, const std::vector< InetAddr > &addrs=std::vector< InetAddr >(), MacVLanMode mode=MacVLanMode::PRIVATE)
adds interface configuration.
Definition: network-config.cpp:97
NetworkInterfaceConfig(const std::string &hostif, const std::string &zoneif, InterfaceType type, const std::vector< InetAddr > &addrs, MacVLanMode mode)
Definition: network-config.hpp:48
Unified ip address.
Definition: network.hpp:56
const std::string & getHostIf() const
Definition: network-config.cpp:32
Configuration file for the code.
const NetworkInterfaceConfig & getInterface(int i) const
Definition: network-config.hpp:133
const std::vector< NetworkInterfaceConfig > & getInterfaces() const
Definition: network-config.hpp:132
void setMTU(int mtu)
Definition: network-config.cpp:52
void setTxLength(int txlen)
Definition: network-config.cpp:62
Actions on network interace in the container.
void setMACAddress(const std::string &mac)
Definition: network-config.cpp:57
#define CARGO_REGISTER(...)
Registers cargo fields within class.
Definition: fields.hpp:74
const std::string & getMACAddress() const
Definition: network-config.cpp:72
int getMTU() const
Definition: network-config.cpp:67
std::vector< InetAddr > mIpAddrList
Definition: network-config.hpp:113
void addInetAddr(const InetAddr &addr)
Definition: network-config.cpp:87
int mMode
Definition: network-config.hpp:98
int mType
Definition: network-config.hpp:97
MacVLanMode
Suported MacVLan modes.
Definition: network.hpp:188
MacVLanMode getMode() const
Definition: network-config.cpp:47
Network interface configuration.
Definition: network-config.hpp:119
InterfaceType
Created interface type.
Definition: network.hpp:179
InterfaceType getType() const
Definition: network-config.cpp:42
lxcpp's exceptions definitions
std::string mMacAddress
Definition: network-config.hpp:110
int mTxLength
Definition: network-config.hpp:111