Commit 4974c609 authored by Aurélien Delrieu's avatar Aurélien Delrieu

[WIP] Specify the TUN/TAP iface name as process argument

TODO: Move bridge management from core to daemon
parent e4bba403
......@@ -57,9 +57,10 @@ extern "C"
/**
* constructor
*/
BlockLanAdaptation::BlockLanAdaptation(const string &name, string lan_iface):
BlockLanAdaptation::BlockLanAdaptation(const string &name, struct la_specific specific):
Block(name),
lan_iface(lan_iface),
tuntap_iface(specific.tuntap_iface),
lan_iface(specific.lan_iface),
is_tap(false)
{
}
......@@ -455,10 +456,10 @@ bool BlockLanAdaptation::allocTunTap(int &fd)
/* create TUN or TAP interface */
LOG(this->log_init, LEVEL_INFO,
"create interface opensand_%s\n",
(this->is_tap ? "tap" : "tun"));
snprintf(ifr.ifr_name, IFNAMSIZ, "opensand_%s",
(this->is_tap ? "tap" : "tun"));
"create %s interface %s\n",
this->is_tap ? "TAP" : "TUN",
this->tuntap_iface.c_str());
snprintf(ifr.ifr_name, IFNAMSIZ, this->tuntap_iface.c_str());
ifr.ifr_flags = (this->is_tap ? IFF_TAP : IFF_TUN);
if(this->is_tap && !this->addInBridge())
{
......@@ -489,7 +490,7 @@ bool BlockLanAdaptation::addInBridge()
int err = -1;
memset(&ifr_br, 0, sizeof(ifr_br));
snprintf(ifr_br.ifr_name, IFNAMSIZ, "%s", br);
snprintf(ifr_br.ifr_name, IFNAMSIZ, "%s", this->tuntap_iface.c_str());
err = br_init();
if(err)
......@@ -537,7 +538,7 @@ bool BlockLanAdaptation::delFromBridge()
return false;
}
err = br_del_interface(br, this->lan_iface.c_str());
err = br_del_interface(this->tuntap_iface.c_str(), this->lan_iface.c_str());
if(err)
{
LOG(this->log_init, LEVEL_ERROR,
......
......@@ -51,6 +51,11 @@
using std::string;
struct la_specific
{
string tuntap_iface;
string lan_iface;
};
/**
* @class BlockLanAdaptation
......@@ -60,7 +65,7 @@ class BlockLanAdaptation: public Block
{
public:
BlockLanAdaptation(const string &name, string lan_iface);
BlockLanAdaptation(const string &name, struct la_specific specific);
~BlockLanAdaptation();
// initialization method
......@@ -69,7 +74,7 @@ class BlockLanAdaptation: public Block
class Upward: public RtUpward
{
public:
Upward(const string &name, string UNUSED(lan_iface)):
Upward(const string &name, struct la_specific UNUSED(specific)):
RtUpward(name),
sarp_table(),
contexts(),
......@@ -135,7 +140,7 @@ class BlockLanAdaptation: public Block
class Downward: public RtDownward
{
public:
Downward(const string &name, string UNUSED(lan_iface)):
Downward(const string &name, struct la_specific UNUSED(specific)):
RtDownward(name),
stats_period_ms(),
contexts(),
......@@ -190,6 +195,8 @@ class BlockLanAdaptation: public Block
private:
/// The TUN/TAP interface name
string tuntap_iface;
/// The LAN interface name
string lan_iface;
......@@ -217,8 +224,6 @@ class BlockLanAdaptation: public Block
* return true on success, false otherwise
*/
bool delFromBridge();
bool tunConfiguration();
};
#endif
......@@ -79,8 +79,9 @@
/**
* Argument treatment
*/
bool init_process(int argc, char **argv,
bool init_process(int argc, char **argv,
string &ip_addr,
string &tuntap_iface,
string &lan_iface,
string &conf_path,
tal_id_t &instance_id)
......@@ -89,11 +90,11 @@ bool init_process(int argc, char **argv,
int opt;
bool output_enabled = true;
bool output_stdout = false;
bool stop = false;
bool stop = false;
char entity[10];
string lib_external_output_path = "";
/* setting environment agent parameters */
while(!stop && (opt = getopt(argc, argv, "-hqdi:a:c:e:")) != EOF)
while(!stop && (opt = getopt(argc, argv, "-hqdi:a:t:l:c:e:")) != EOF)
{
switch(opt)
{
......@@ -113,6 +114,10 @@ bool init_process(int argc, char **argv,
// get local IP address
ip_addr = optarg;
break;
case 't':
// get TUN/TAP interface name
tuntap_iface = optarg;
break;
case 'l':
// get lan interface name
lan_iface = optarg;
......@@ -128,12 +133,13 @@ bool init_process(int argc, char **argv,
case 'h':
case '?':
fprintf(stderr, "usage: %s [-h] [[-q] [-d] -i instance_id -a ip_address "
"-l lan_iface -c conf_path -e lib_ext_output_path\n",
"-t tuntap_iface -l lan_iface -c conf_path -e lib_ext_output_path\n",
argv[0]);
fprintf(stderr, "\t-h print this message\n");
fprintf(stderr, "\t-q disable output\n");
fprintf(stderr, "\t-d enable output debug events\n");
fprintf(stderr, "\t-a <ip_address> set the IP address for emulation\n");
fprintf(stderr, "\t-t <tuntap_iface> set the GW TUN/TAP interface name\n");
fprintf(stderr, "\t-l <lan_iface> set the GW lan interface name\n");
fprintf(stderr, "\t-i <instance> set the instance id\n");
fprintf(stderr, "\t-c <conf_path> specify the configuration path\n");
......@@ -142,7 +148,7 @@ bool init_process(int argc, char **argv,
break;
}
}
if(lib_external_output_path != "")
{
sprintf(entity, "gw%d", instance_id);
......@@ -156,7 +162,7 @@ bool init_process(int argc, char **argv,
else
{
// output initialization
if(!Output::init(output_enabled))
if(!Output::init(output_enabled))
{
stop = true;
fprintf(stderr, "Unable to initialize output library\n");
......@@ -183,6 +189,13 @@ bool init_process(int argc, char **argv,
return false;
}
if(tuntap_iface.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
"missing mandatory TUN/TAP interface name option");
return false;
}
if(lan_iface.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
......@@ -206,9 +219,11 @@ int main(int argc, char **argv)
struct sched_param param;
bool init_ok;
string ip_addr;
string tuntap_iface;
string lan_iface;
tal_id_t mac_id = 0;
struct sc_specific specific;
struct la_specific laspecific;
struct sc_specific scspecific;
string satellite_type;
......@@ -233,7 +248,7 @@ int main(int argc, char **argv)
int is_failure = 1;
// retrieve arguments on command line
init_ok = init_process(argc, argv, ip_addr, lan_iface, conf_path, mac_id);
init_ok = init_process(argc, argv, ip_addr, tuntap_iface, lan_iface, conf_path, mac_id);
plugin_conf_path = conf_path + string("plugins/");
......@@ -264,9 +279,9 @@ int main(int argc, char **argv)
progname);
goto quit;
}
OpenSandConf::loadConfig();
// read all packages debug levels
if(!Conf::loadLevels(levels, spec_level))
{
......@@ -278,7 +293,7 @@ int main(int argc, char **argv)
Output::setLevels(levels, spec_level);
// retrieve the type of satellite from configuration
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
SATELLITE_TYPE,
satellite_type))
{
......@@ -299,10 +314,12 @@ int main(int argc, char **argv)
}
// instantiate all blocs
laspecific.tuntap_iface = tuntap_iface;
laspecific.lan_iface = lan_iface;
block_lan_adaptation = Rt::createBlock<BlockLanAdaptation,
BlockLanAdaptation::Upward,
BlockLanAdaptation::Downward,
string>("LanAdaptation", NULL, lan_iface);
struct la_specific>("LanAdaptation", NULL, laspecific);
if(!block_lan_adaptation)
{
DFLTLOG(LEVEL_CRITICAL,
......@@ -355,14 +372,14 @@ int main(int argc, char **argv)
goto release_plugins;
}
specific.ip_addr = ip_addr;
specific.tal_id = mac_id;
scspecific.ip_addr = ip_addr;
scspecific.tal_id = mac_id;
block_sat_carrier = Rt::createBlock<BlockSatCarrier,
BlockSatCarrier::Upward,
BlockSatCarrier::Downward,
struct sc_specific>("SatCarrier",
block_phy_layer,
specific);
scspecific);
if(!block_sat_carrier)
{
DFLTLOG(LEVEL_CRITICAL,
......
......@@ -74,6 +74,7 @@
* Argument treatment
*/
bool init_process(int argc, char **argv,
string &tuntap_iface,
string &lan_iface,
tal_id_t &instance_id,
string &interconnect_addr,
......@@ -86,9 +87,9 @@ bool init_process(int argc, char **argv,
bool stop = false;
string lib_external_output_path = "";
char entity[10];
/* setting environment agent parameters */
while(!stop && (opt = getopt(argc, argv, "-hqdi:u:w:c:e:")) != EOF)
while(!stop && (opt = getopt(argc, argv, "-hqdi:t:l:u:w:c:e:")) != EOF)
{
switch(opt)
{
......@@ -104,6 +105,10 @@ bool init_process(int argc, char **argv,
// get instance id
instance_id = atoi(optarg);
break;
case 't':
// get TUN/TAP interface name
tuntap_iface = optarg;
break;
case 'l':
// get lan interface name
lan_iface = optarg;
......@@ -123,11 +128,12 @@ bool init_process(int argc, char **argv,
case 'h':
case '?':
fprintf(stderr, "usage: %s [-h] [[-q] [-d] -i instance_id "
"-l lan_iface -w interconnect_addr -c conf_path -e lib_ext_output_path\n",
"-t tuntap_iface -l lan_iface -w interconnect_addr -c conf_path -e lib_ext_output_path\n",
argv[0]);
fprintf(stderr, "\t-h print this message\n");
fprintf(stderr, "\t-q disable output\n");
fprintf(stderr, "\t-d enable output debug events\n");
fprintf(stderr, "\t-t <tuntap_iface> set the GW TUN/TAP interface name\n");
fprintf(stderr, "\t-l <lan_iface> set the GW lan interface name\n");
fprintf(stderr, "\t-i <instance> set the instance id\n");
fprintf(stderr, "\t-w <interconnect_addr> set the interconnect IP address\n");
......@@ -151,7 +157,7 @@ bool init_process(int argc, char **argv,
else
{
// output initialization
if(!Output::init(output_enabled))
if(!Output::init(output_enabled))
{
stop = true;
fprintf(stderr, "Unable to initialize output library\n");
......@@ -169,20 +175,27 @@ bool init_process(int argc, char **argv,
DFLTLOG(LEVEL_NOTICE,
"starting output\n");
if(tuntap_iface.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
"missing mandatory TUN/TAP interface name option");
return false;
}
if(lan_iface.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
"missing mandatory lan interface name option");
return false;
}
if(conf_path.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
"missing mandatory configuration path option");
return false;
}
if(interconnect_addr.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
......@@ -197,9 +210,11 @@ int main(int argc, char **argv)
const char *progname = argv[0];
struct sched_param param;
bool init_ok;
string tuntap_iface;
string lan_iface;
tal_id_t mac_id = 0;
string interconnect_addr;
struct la_specific spec_la;
struct ic_specific spec_ic;
string conf_path;
......@@ -222,7 +237,7 @@ int main(int argc, char **argv)
int is_failure = 1;
// retrieve arguments on command line
init_ok = init_process(argc, argv, lan_iface, mac_id,
init_ok = init_process(argc, argv, tuntap_iface, lan_iface, mac_id,
interconnect_addr, conf_path);
plugin_conf_path = conf_path + string("plugins/");
......@@ -254,9 +269,9 @@ int main(int argc, char **argv)
progname);
goto quit;
}
OpenSandConf::loadConfig();
// read all packages debug levels
if(!Conf::loadLevels(levels, spec_level))
{
......@@ -276,10 +291,12 @@ int main(int argc, char **argv)
}
// instantiate all blocs
spec_la.tuntap_iface = tuntap_iface;
spec_la.lan_iface = lan_iface;
block_lan_adaptation = Rt::createBlock<BlockLanAdaptation,
BlockLanAdaptation::Upward,
BlockLanAdaptation::Downward,
string>("LanAdaptation", NULL, lan_iface);
struct la_specific>("LanAdaptation", NULL, spec_la);
if(!block_lan_adaptation)
{
DFLTLOG(LEVEL_CRITICAL,
......
......@@ -37,7 +37,7 @@
*
* <pre>
*
* :
* :
* :
* Block Interconnect Upward
* |
......@@ -69,7 +69,7 @@
/**
* Argument treatment
*/
bool init_process(int argc, char **argv,
bool init_process(int argc, char **argv,
string &ip_addr,
tal_id_t &instance_id,
string &interconnect_addr,
......@@ -80,7 +80,7 @@ bool init_process(int argc, char **argv,
bool output_stdout = false;
bool stop = false;
string lib_external_output_path = "";
char entity[10];
char entity[10];
/* setting environment agent parameters */
while(!stop && (opt = getopt(argc, argv, "-hqdi:a:u:w:c:e:")) != EOF)
{
......@@ -133,7 +133,7 @@ bool init_process(int argc, char **argv,
}
if(lib_external_output_path != "")
{
{
sprintf(entity, "gw%d", instance_id);
// external output initialization
if(!Output::initExt(output_enabled, (const char *)entity, lib_external_output_path.c_str()))
......@@ -145,7 +145,7 @@ bool init_process(int argc, char **argv,
else
{
// output initialization
if(!Output::init(output_enabled))
if(!Output::init(output_enabled))
{
stop = true;
fprintf(stderr, "Unable to initialize output library\n");
......@@ -253,9 +253,9 @@ int main(int argc, char **argv)
progname);
goto quit;
}
OpenSandConf::loadConfig();
// read all packages debug levels
if(!Conf::loadLevels(levels, spec_level))
{
......@@ -267,7 +267,7 @@ int main(int argc, char **argv)
Output::setLevels(levels, spec_level);
// retrieve the type of satellite from configuration
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
SATELLITE_TYPE,
satellite_type))
{
......
......@@ -84,7 +84,7 @@ bool init_process(int argc, char **argv, string &ip_addr, string &conf_path)
bool output_stdout = false;
bool stop = false;
string lib_external_output_path = "";
char entity[10];
char entity[10];
/* setting environment agent parameters */
while(!stop && (opt = getopt(argc, argv, "-hqda:c:e:")) != EOF)
{
......@@ -138,7 +138,7 @@ bool init_process(int argc, char **argv, string &ip_addr, string &conf_path)
else
{
// output initialization
if(!Output::init(output_enabled))
if(!Output::init(output_enabled))
{
stop = true;
fprintf(stderr, "Unable to initialize output library\n");
......@@ -204,7 +204,7 @@ int main(int argc, char **argv)
OutputEvent *status;
int is_failure = 1;
// retrieve arguments on command line
init_ok = init_process(argc, argv, ip_addr, conf_path);
......@@ -252,7 +252,7 @@ int main(int argc, char **argv)
Output::setLevels(levels, spec_level);
// retrieve the type of satellite from configuration
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
SATELLITE_TYPE,
satellite_type))
{
......@@ -336,8 +336,7 @@ int main(int argc, char **argv)
"%s: cannot create the SatCarrier block\n", progname);
goto release_plugins;
}
DFLTLOG(LEVEL_DEBUG,
"All blocks are created, start\n");
......@@ -348,7 +347,7 @@ int main(int argc, char **argv)
}
if(!Output::finishInit())
{
DFLTLOG(LEVEL_NOTICE,
DFLTLOG(LEVEL_NOTICE,
"%s: failed to init the output => disable it\n",
progname);
}
......
......@@ -81,6 +81,7 @@
*/
bool init_process(int argc, char **argv,
string &ip_addr,
string &tuntap_iface,
string &lan_iface,
string &conf_path,
tal_id_t &instance_id)
......@@ -92,7 +93,7 @@ bool init_process(int argc, char **argv,
string lib_external_output_path = "";
char entity[10];
/* setting environment agent parameters */
while(!stop && (opt = getopt(argc, argv, "-hqdi:a:l:c:e:")) != EOF)
while(!stop && (opt = getopt(argc, argv, "-hqdi:a:t:l:c:e:")) != EOF)
{
switch(opt)
{
......@@ -112,6 +113,10 @@ bool init_process(int argc, char **argv,
// get local IP address
ip_addr = optarg;
break;
case 't':
// get TUN/TAP interface name
tuntap_iface = optarg;
break;
case 'l':
// get lan interface name
lan_iface = optarg;
......@@ -127,12 +132,13 @@ bool init_process(int argc, char **argv,
case 'h':
case '?':
fprintf(stderr, "usage: %s [-h] [[-q] [-d] -i instance_id -a ip_address "
"-l lan_iface -c conf_path -e lib_ext_output_path\n",
"-t tuntap_iface -l lan_iface -c conf_path -e lib_ext_output_path\n",
argv[0]);
fprintf(stderr, "\t-h print this message\n");
fprintf(stderr, "\t-q disable output\n");
fprintf(stderr, "\t-d enable output debug events\n");
fprintf(stderr, "\t-a <ip_address> set the IP address for emulation\n");
fprintf(stderr, "\t-t <tuntap_iface> set the ST TUN/TAP interface name\n");
fprintf(stderr, "\t-l <lan_iface> set the ST lan interface name\n");
fprintf(stderr, "\t-i <instance> set the instance id\n");
fprintf(stderr, "\t-c <conf_path> specify the configuration path\n");
......@@ -155,7 +161,7 @@ bool init_process(int argc, char **argv,
else
{
// output initialization
if(!Output::init(output_enabled))
if(!Output::init(output_enabled))
{
stop = true;
fprintf(stderr, "Unable to initialize output library\n");
......@@ -181,6 +187,13 @@ bool init_process(int argc, char **argv,
return false;
}
if(tuntap_iface.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
"missing mandatory TUN/TAP interface name option\n");
return false;
}
if(lan_iface.size() == 0)
{
DFLTLOG(LEVEL_CRITICAL,
......@@ -205,9 +218,11 @@ int main(int argc, char **argv)
struct sched_param param;
bool init_ok;
string ip_addr;
string tuntap_iface;
string lan_iface;
tal_id_t mac_id;
struct sc_specific specific;
struct la_specific laspecific;
struct sc_specific scspecific;
string satellite_type;
......@@ -232,7 +247,7 @@ int main(int argc, char **argv)
int is_failure = 1;
// retrieve arguments on command line
init_ok = init_process(argc, argv, ip_addr, lan_iface, conf_path, mac_id);
init_ok = init_process(argc, argv, ip_addr, tuntap_iface, lan_iface, conf_path, mac_id);
plugin_conf_path = conf_path + string("plugins/");
......@@ -263,9 +278,9 @@ int main(int argc, char **argv)
progname);
goto quit;
}
OpenSandConf::loadConfig();
// read all packages debug levels
if(!Conf::loadLevels(levels, spec_level))
{
......@@ -277,7 +292,7 @@ int main(int argc, char **argv)
Output::setLevels(levels, spec_level);
// retrieve the type of satellite from configuration
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
if(!Conf::getValue(Conf::section_map[COMMON_SECTION],
SATELLITE_TYPE,
satellite_type))
{
......@@ -299,10 +314,12 @@ int main(int argc, char **argv)
// instantiate all blocs
// TODO remove lan iface once daemon handles bridging part
laspecific.tuntap_iface = tuntap_iface;
laspecific.lan_iface = lan_iface;
block_lan_adaptation = Rt::createBlock<BlockLanAdaptation,
BlockLanAdaptation::Upward,
BlockLanAdaptation::Downward,
string>("LanAdaptation", NULL, lan_iface);
struct la_specific>("LanAdaptation", NULL, laspecific);
if(!block_lan_adaptation)
{
DFLTLOG(LEVEL_CRITICAL,
......@@ -356,14 +373,14 @@ int main(int argc, char **argv)
goto release_plugins;
}
specific.ip_addr = ip_addr;
specific.tal_id = mac_id;
scspecific.ip_addr = ip_addr;
scspecific.tal_id = mac_id;
block_sat_carrier = Rt::createBlock<BlockSatCarrier,
BlockSatCarrier::Upward,
BlockSatCarrier::Downward,
struct sc_specific>("SatCarrier",
block_phy_layer,
specific);
scspecific);
if(!block_sat_carrier)
{
DFLTLOG(LEVEL_CRITICAL,
......
......@@ -253,6 +253,13 @@ class MachineController:
lan_iface = ''
if component not in {SAT, GW_PHY}:
lan_iface = '-l ' + self._machine_model.get_lan_interface()
print('get_lan_adaptation: {}'.format(
self._machine_model.get_lan_adaptation()
))
if self._machine_model.get_lan_adaptation()['0'] == 'IP':
lan_iface += ' -t opensand_tun'
else:
lan_iface += ' -t opensand_tap'
output_libpath = self._machine_model.get_output_libpath()
if output_libpath:
output_libpath = '-e ' + output_libpath
......@@ -264,19 +271,17 @@ class MachineController:
output_libpath,
CONF_DESTINATION_PATH)
elif component == GW_PHY:
command_line = '%s %s -a %s -n %s -u %s -w %s %s -c %s' % \
command_line = '%s %s -a %s -u %s -w %s %s -c %s' % \
(bin_file, instance_param,
self._machine_model.get_emulation_address(),
self._machine_model.get_emulation_interface(),
self._machine_model.get_interconnect_interface(),
self._machine_model.get_interconnect_address(),
output_libpath,
CONF_DESTINATION_PATH)
else:
command_line = '%s -a %s -n %s %s %s %s -c %s' % \
command_line = '%s -a %s %s %s %s -c %s' % \
(bin_file,
self._machine_model.get_emulation_address(),
self._machine_model.get_emulation_interface(),
lan_iface, instance_param,
output_libpath,
CONF_DESTINATION_PATH)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment