mininet-sample/core/topo.py

537 lines
20 KiB
Python
Raw Normal View History

2020-06-24 08:36:26 +00:00
from .parameter import Parameter
2020-06-26 09:17:00 +00:00
import logging
2020-06-24 09:26:56 +00:00
import math
class NetemAt(object):
2020-06-29 07:51:55 +00:00
"""
Class representing a netem command to be run after some time
"""
2020-06-24 10:19:05 +00:00
def __init__(self, at, cmd):
self.at = at
self.cmd = cmd
self.delta = 0
2020-06-24 09:26:56 +00:00
2020-06-24 10:19:05 +00:00
def __str__(self):
return "netem at {} ({}) will be {}".format(self.at, self.delta, self.cmd)
2020-06-24 09:26:56 +00:00
class LinkCharacteristics(object):
"""
Network characteristics associated to a link
Attributes:
id the identifier of the link
delay the one-way delay introduced by the link in ms
queue_size the size of the link buffer, in packets
bandwidth the bandwidth of the link in Mbps
loss the random loss rate in percentage
queuing_delay the maximum time that a packet can stay in the link buffer (computed over queue_size)
netem_at list of NetemAt instances applicable to the link
backup integer indicating if this link is a backup one or not (useful for MPTCP)
"""
def __init__(self, id, delay, queue_size, bandwidth, loss, backup=False):
self.id = id
self.delay = delay
self.queue_size = queue_size
self.bandwidth = bandwidth
self.loss = loss
self.queuing_delay = str(self.extract_queuing_delay(queue_size, bandwidth, delay))
self.netem_at = []
self.backup = backup
2020-06-24 09:26:56 +00:00
def bandwidth_delay_product_divided_by_mtu(self):
"""
Get the bandwidth-delay product in terms of packets (hence, dividing by the MTU)
"""
2020-06-24 09:26:56 +00:00
rtt = 2 * float(self.delay)
""" Since bandwidth is in Mbps and rtt in ms """
bandwidth_delay_product = (float(self.bandwidth) * 125000.0) * (rtt / 1000.0)
return int(math.ceil(bandwidth_delay_product * 1.0 / 1500.0))
2020-06-24 09:26:56 +00:00
def buffer_size(self):
"""
Return the buffer size in bytes
"""
return (1500.0 * self.bandwidth_delay_product_divided_by_mtu()) + \
(float(self.bandwidth) * 1000.0 * float(self.queuing_delay) / 8)
2020-06-24 09:26:56 +00:00
def extract_queuing_delay(self, queue_size, bandwidth, delay, mtu=1500):
queuing_delay = (int(queue_size) * int(mtu) * 8.0 * 1000.0) / \
(float(bandwidth) * 1024 * 1024)
return max(int(queuing_delay), 1)
2020-06-24 09:26:56 +00:00
def add_netem_at(self, n):
if len(self.netem_at) == 0:
2020-06-24 09:26:56 +00:00
n.delta = n.at
self.netem_at.append(n)
2020-06-24 09:26:56 +00:00
else:
if n.at > self.netem_at[-1].at:
n.delta = n.at - self.netem_at[-1].at
self.netem_at.append(n)
2020-06-24 09:26:56 +00:00
else:
logging.error("{}: not taken into account because not specified in order in the topo param file".format(n))
def build_bandwidth_cmd(self, ifname):
2020-06-29 10:46:07 +00:00
return "tc qdisc del {} root ; tc qdisc add dev {} root handle 5:0 tbf rate {}mbit burst 15000 limit {}".format(
ifname, ifname, self.bandwidth, self.buffer_size())
def build_changing_bandwidth_cmd(self, ifname):
return "&&".join(
2020-06-29 10:46:07 +00:00
["sleep {} && {} ".format(
n.delta, self.build_bandwidth_cmd(ifname)) for n in self.netem_at]
+ ["true &"]
)
2020-06-29 10:46:07 +00:00
def build_netem_cmd(self, ifname, cmd):
return "tc qdisc del dev {} root ; tc qdisc add dev {} root handle 10: netem {} delay {}ms limit 50000".format(
ifname, ifname, cmd, self.delay)
def build_changing_netem_cmd(self, ifname):
return "&&".join(
2020-06-29 10:46:07 +00:00
["sleep {} && {} ".format(
n.delta, self.build_netem_cmd(ifname, n.cmd)) for n in self.netem_at]
+ ["true &"]
)
2020-06-29 10:46:07 +00:00
def clean_policing_cmd(self, ifname):
return "tc qdisc del dev {} ingress ".format(ifname)
def build_policing_cmd(self, ifname):
2020-06-29 10:46:07 +00:00
""" For some reason, the delete can break everything """
return "tc qdisc add dev {} handle ffff: ingress ; \
tc filter add dev {} parent ffff: u32 match u32 0 0 police rate {}mbit burst {} drop".format(
ifname, ifname, self.bandwidth, int(self.buffer_size()) * 1.2)
def build_changing_policing_cmd(self, ifname):
return "&&".join(
2020-06-29 10:46:07 +00:00
["sleep {} && {} ".format(
n.delta, self.build_policing_cmd(ifname)) for n in self.netem_at]
+ ["true &"]
)
def as_dict(self):
2020-06-29 10:46:07 +00:00
"""
Notably used by BottleneckLink
"""
return {
"bw": float(self.bandwidth),
"delay": "{}ms".format(self.delay),
"loss": float(self.loss),
"max_queue_size": int(self.queue_size)
}
2020-06-24 09:26:56 +00:00
def __str__(self):
return """
Link id: {}
Delay: {}
Queue Size: {}
Bandwidth: {}
Loss: {}
Backup: {}
""".format(self.id, self.delay, self.queue_size, self.bandwidth, self.loss, self.backup) + \
"".join(["\t {} \n".format(n) for n in self.netem_at])
2020-06-24 09:26:56 +00:00
2020-06-24 08:36:26 +00:00
class TopoParameter(Parameter):
2020-06-29 07:51:55 +00:00
LEFT_SUBNET = "leftSubnet"
RIGHT_SUBNET = "rightSubnet"
NETEM_AT = "netem_at_"
CHANGE_NETEM = "changeNetem"
DEFAULT_PARAMETERS = {
LEFT_SUBNET: "10.1.",
RIGHT_SUBNET: "10.2.",
CHANGE_NETEM: "false",
}
2020-06-24 10:19:05 +00:00
2020-06-25 12:56:47 +00:00
def __init__(self, parameter_filename):
Parameter.__init__(self, parameter_filename)
2020-06-29 07:51:55 +00:00
self.default_parameters.update(TopoParameter.DEFAULT_PARAMETERS)
self.link_characteristics = []
self.load_link_characteristics()
self.load_netem_at()
logging.info(self)
def load_netem_at(self):
if not self.get(TopoParameter.CHANGE_NETEM) == "yes":
2020-06-24 10:19:05 +00:00
return
2020-06-25 12:56:47 +00:00
for k in sorted(self.parameters):
2020-06-29 07:51:55 +00:00
if k.startswith(TopoParameter.NETEM_AT):
link_id = int(k[len(TopoParameter.NETEM_AT):])
2020-06-25 12:56:47 +00:00
val = self.parameters[k]
2020-06-24 10:19:05 +00:00
if not isinstance(val, list):
tmp = val
val = []
val.append(tmp)
2020-06-29 07:51:55 +00:00
self.load_netem_at_list(link_id, val)
2020-06-24 10:19:05 +00:00
2020-06-29 07:51:55 +00:00
def load_netem_at_list(self, link_id, nlist):
2020-06-24 10:19:05 +00:00
for n in nlist:
2020-06-29 07:51:55 +00:00
try:
at, cmd = n.split(",")
na = NetemAt(float(at), cmd)
if link_id < len(self.link_characteristics):
self.link_characteristics[id].add_netem_at(na)
2020-06-24 10:19:05 +00:00
else:
2020-06-29 07:51:55 +00:00
logging.error("Unable to set netem for link {}; only have {} links".format(
link_id, len(self.link_characteristics)))
except ValueError as e:
logging.error("Unable to set netem for link {}: {}".format(link_id, n))
logging.info(self.link_characteristics[link_id].netem_at)
2020-06-24 10:19:05 +00:00
2020-06-29 07:51:55 +00:00
def load_link_characteristics(self):
"""
CAUTION: the path_i in config file is not taken into account. Hence place them in
increasing order in the topo parameter file!
"""
2020-06-24 10:19:05 +00:00
i = 0
2020-06-25 12:56:47 +00:00
for k in sorted(self.parameters):
2020-06-29 07:51:55 +00:00
# TODO FIXME rewrite this function
2020-06-24 10:19:05 +00:00
if k.startswith("path"):
2020-06-25 12:56:47 +00:00
tab = self.parameters[k].split(",")
2020-06-24 10:19:05 +00:00
bup = False
loss = "0.0"
if len(tab) == 5:
loss = tab[3]
2020-06-29 07:51:55 +00:00
bup = tab[4].lower() == 'true'
2020-06-24 10:19:05 +00:00
if len(tab) == 4:
try:
loss = float(tab[3])
loss = tab[3]
except ValueError:
2020-06-29 07:51:55 +00:00
bup = tab[3].lower() == 'true'
2020-06-24 10:19:05 +00:00
if len(tab) == 3 or len(tab) == 4 or len(tab) == 5:
2020-06-29 07:51:55 +00:00
path = LinkCharacteristics(i, tab[0],
2020-06-24 10:19:05 +00:00
tab[1], tab[2], loss, bup)
2020-06-29 07:51:55 +00:00
self.link_characteristics.append(path)
2020-06-24 10:19:05 +00:00
i = i + 1
else:
2020-06-29 07:51:55 +00:00
logging.warning("Ignored path {}".format(self.parameters[k]))
2020-06-24 10:19:05 +00:00
def __str__(self):
2020-06-29 07:51:55 +00:00
s = "{}".format(super(TopoParameter, self).__str__())
s += "".join(["{}".format(lc) for lc in self.link_characteristics])
2020-06-24 10:19:05 +00:00
return s
2020-06-24 08:36:26 +00:00
2020-06-29 10:46:07 +00:00
class BottleneckLink(object):
"""
Representation of a bottleneck link having limited bandwidth, a buffer,
experiencing propagation delay and introducing packet losses.
A bottleneck link has the following actual representation:
bs0 -- bs1 -- bs2 -- bs3
Where bs0 (resp. bs3) is the left (resp. right) side of the link, and having
TC commands for the packet flow s0 -> s3 as follows:
- Policing command to implement buffer on ingress of bs1 from bs0
- Shaping command to implement bandwidth on egress of bs1 to bs2
- Netem command to implement delay and loss on egress of bs2 to bs3
"""
BOTTLENECK_SWITCH_NAME_PREFIX = "bs"
def __init__(self, topo_builder, topo, link_characteristics):
self.link_characteristics = link_characteristics
self.topo = topo
self.bs0 = topo_builder.add_switch("{}_{}_0".format(
BottleneckLink.BOTTLENECK_SWITCH_NAME_PREFIX, self.link_characteristics.id))
self.bs1 = topo_builder.add_switch("{}_{}_1".format(
BottleneckLink.BOTTLENECK_SWITCH_NAME_PREFIX, self.link_characteristics.id))
self.bs2 = topo_builder.add_switch("{}_{}_2".format(
BottleneckLink.BOTTLENECK_SWITCH_NAME_PREFIX, self.link_characteristics.id))
self.bs3 = topo_builder.add_switch("{}_{}_3".format(
BottleneckLink.BOTTLENECK_SWITCH_NAME_PREFIX, self.link_characteristics.id))
topo_builder.add_link(self.bs0, self.bs1)
topo_builder.add_link(self.bs1, self.bs2)
topo_builder.add_link(self.bs2, self.bs3)
def configure_bottleneck(self):
2020-06-29 12:22:39 +00:00
# Required to retrieve actual nodes
self.bs0 = self.topo.get_host(self.bs0)
self.bs1 = self.topo.get_host(self.bs1)
self.bs2 = self.topo.get_host(self.bs2)
self.bs3 = self.topo.get_host(self.bs3)
2020-06-29 12:13:47 +00:00
bs1_interface_names = self.topo.get_interface_names(self.bs1)
bs2_interface_names = self.topo.get_interface_names(self.bs2)
2020-06-29 10:46:07 +00:00
# Flow bs0 -> bs3
# Only once
2020-06-29 12:13:47 +00:00
clean_policing_cmd = self.link_characteristics.clean_policing_cmd(bs1_interface_names[0])
2020-06-29 10:46:07 +00:00
logging.info(clean_policing_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs1, clean_policing_cmd)
policing_cmd = self.link_characteristics.build_policing_cmd(bs1_interface_names[0])
2020-06-29 10:46:07 +00:00
logging.info(policing_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs1, policing_cmd)
shaping_cmd = self.link_characteristics.build_bandwidth_cmd(bs1_interface_names[-1])
2020-06-29 10:46:07 +00:00
logging.info(shaping_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs1, shaping_cmd)
netem_cmd = self.link_characteristics.build_netem_cmd(bs2_interface_names[-1],
2020-06-29 10:46:07 +00:00
"loss {}".format(self.link_characteristics.loss))
logging.info(netem_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs2, netem_cmd)
2020-06-29 10:46:07 +00:00
# Flow bs3 -> bs0
2020-06-29 12:13:47 +00:00
policing_cmd = self.link_characteristics.build_policing_cmd(bs2_interface_names[-1])
2020-06-29 10:46:07 +00:00
logging.info(policing_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs2, policing_cmd)
shaping_cmd = self.link_characteristics.build_bandwidth_cmd(bs2_interface_names[0])
2020-06-29 10:46:07 +00:00
logging.info(shaping_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs2, shaping_cmd)
netem_cmd = self.link_characteristics.build_netem_cmd(bs1_interface_names[0],
2020-06-29 10:46:07 +00:00
"loss {}".format(self.link_characteristics.loss))
logging.info(netem_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs1, netem_cmd)
2020-06-29 10:46:07 +00:00
def configure_changing_bottleneck(self):
2020-06-29 12:13:47 +00:00
bs1_interface_names = self.topo.get_interface_names(self.bs1)
bs2_interface_names = self.topo.get_interface_names(self.bs2)
2020-06-29 10:46:07 +00:00
# Flow bs0 -> bs3
2020-06-29 12:13:47 +00:00
policing_cmd = self.link_characteristics.build_changing_policing_cmd(bs1_interface_names[0])
2020-06-29 10:46:07 +00:00
logging.info(policing_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs1, policing_cmd)
shaping_cmd = self.link_characteristics.build_changing_bandwidth_cmd(bs1_interface_names[-1])
2020-06-29 10:46:07 +00:00
logging.info(shaping_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs1, shaping_cmd)
netem_cmd = self.link_characteristics.build_changing_netem_cmd(bs2_interface_names[-1])
2020-06-29 10:46:07 +00:00
logging.info(netem_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs2, netem_cmd)
2020-06-29 10:46:07 +00:00
# Flow bs3 -> bs0
2020-06-29 12:13:47 +00:00
policing_cmd = self.link_characteristics.build_changing_policing_cmd(bs2_interface_names[-1])
2020-06-29 10:46:07 +00:00
logging.info(policing_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs2, policing_cmd)
shaping_cmd = self.link_characteristics.build_changing_bandwidth_cmd(bs2_interface_names[0])
2020-06-29 10:46:07 +00:00
logging.info(shaping_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs2, shaping_cmd)
netem_cmd = self.link_characteristics.build_changing_netem_cmd(bs1_interface_names[0])
2020-06-29 10:46:07 +00:00
logging.info(netem_cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(self.bs1, netem_cmd)
2020-06-29 10:46:07 +00:00
def get_left(self):
return self.bs0
def get_right(self):
return self.bs3
2020-06-24 08:54:44 +00:00
class Topo(object):
2020-06-24 10:28:44 +00:00
"""
2020-06-24 14:11:54 +00:00
Base class to instantiate a topology.
2020-06-24 10:28:44 +00:00
2020-06-29 10:46:07 +00:00
The network topology has always the following elements:
- a (set of) client(s)
- a (set of) router(s)
- a (set of) server(s)
- a set of bottleneck links
2020-06-24 14:11:54 +00:00
This class is not instantiable as it. You must define a child class with the
`NAME` attribute.
2020-06-29 07:51:55 +00:00
Attributes:
topo_builder instance of TopoBuilder
topo_parameter instance of TopoParameter
change_netem boolean indicating if netem must be changed
log_file file descriptor logging commands relative to the topo
2020-06-24 14:11:54 +00:00
"""
MININET_BUILDER = "mininet"
TOPO_ATTR = "topoType"
2020-06-29 07:51:55 +00:00
SWITCH_NAME_PREFIX = "s"
ROUTER_NAME_PREFIX = "r"
CLIENT_NAME = "Client"
SERVER_NAME = "Server"
ROUTER_NAME = "Router"
CMD_LOG_FILENAME = "command.log"
def __init__(self, topo_builder, topo_parameter):
self.topo_builder = topo_builder
self.topo_parameter = topo_parameter
self.change_netem = topo_parameter.get(TopoParameter.CHANGE_NETEM).lower() == "yes"
self.log_file = open(Topo.CMD_LOG_FILENAME, 'w')
2020-06-29 10:46:07 +00:00
self.clients = []
self.routers = []
self.servers = []
self.bottleneck_links = []
2020-06-29 07:51:55 +00:00
def get_link_characteristics(self):
return self.topo_parameter.link_characteristics
2020-06-24 10:19:05 +00:00
def command_to(self, who, cmd):
2020-06-29 07:51:55 +00:00
self.log_file.write("{} : {}\n".format(who, cmd))
return self.topo_builder.command_to(who, cmd)
2020-06-24 10:19:05 +00:00
def command_global(self, cmd):
2020-06-24 10:19:05 +00:00
"""
mainly use for not namespace sysctl.
"""
2020-06-29 07:51:55 +00:00
self.log_file.write("Global : {}\n".format(cmd))
return self.topo_builder.command_global(cmd)
2020-06-24 10:19:05 +00:00
2020-06-29 10:46:07 +00:00
def client_count(self):
return len(self.clients)
def get_client(self, index):
return self.clients[index]
def get_router(self, index):
return self.routers[index]
def get_server(self, index):
return self.servers[index]
def router_count(self):
return len(self.routers)
def server_count(self):
return len(self.servers)
def bottleneck_link_count(self):
return len(self.bottleneck_links)
def get_host(self, who):
2020-06-29 07:51:55 +00:00
return self.topo_builder.get_host(who)
2020-06-24 10:19:05 +00:00
2020-06-29 12:13:47 +00:00
def get_interface_names(self, who):
return self.topo_builder.get_interface_names(who)
2020-06-29 07:51:55 +00:00
def add_host(self, host):
return self.topo_builder.add_host(host)
2020-06-24 10:19:05 +00:00
2020-06-29 07:51:55 +00:00
def add_switch(self, switch):
return self.topo_builder.add_switch(switch)
2020-06-24 10:19:05 +00:00
2020-06-29 07:51:55 +00:00
def add_link(self, from_a, to_b, **kwargs):
self.topo_builder.add_link(from_a, to_b, **kwargs)
2020-06-24 10:19:05 +00:00
2020-06-29 10:46:07 +00:00
def add_bottleneck_link(self, from_a, to_b, link_characteristics=None, bottleneck_link=None):
"""
If bottleneck_link is None, create a bottleneck link with parameters kwargs,
otherwise just connect it to from_a and to_b and returns the bottleneck_link
"""
if bottleneck_link is None:
bottleneck_link = BottleneckLink(self.topo_builder, self, link_characteristics)
self.bottleneck_links.append(bottleneck_link)
self.topo_builder.add_link(from_a, bottleneck_link.get_left())
self.topo_builder.add_link(bottleneck_link.get_right(), to_b)
return bottleneck_link
def get_cli(self):
2020-06-29 07:51:55 +00:00
self.topo_builder.get_cli()
2020-06-24 10:19:05 +00:00
def start_network(self):
2020-06-29 07:51:55 +00:00
self.topo_builder.start_network()
2020-06-24 10:19:05 +00:00
2020-06-29 07:51:55 +00:00
def close_log_file(self):
self.log_file.close()
2020-06-24 10:19:05 +00:00
def stop_network(self):
2020-06-29 07:51:55 +00:00
self.topo_builder.stop_network()
2020-06-24 08:36:26 +00:00
2020-06-24 08:54:44 +00:00
class TopoConfig(object):
2020-06-24 10:28:44 +00:00
"""
2020-06-24 14:11:54 +00:00
Base class to instantiate a topology.
2020-06-24 10:28:44 +00:00
2020-06-24 14:11:54 +00:00
This class is not instantiable as it. You must define a child class with the
`NAME` attribute.
"""
2020-06-24 08:36:26 +00:00
def __init__(self, topo, param):
self.topo = topo
self.param = param
def configure_network(self):
2020-06-29 07:51:55 +00:00
logging.debug("Configure network in TopoConfig")
self.configure_interfaces()
self.configure_routing()
2020-06-24 08:36:26 +00:00
2020-06-26 09:17:00 +00:00
def disable_tso(self):
"""
Disable TSO on all interfaces
"""
2020-06-29 10:46:07 +00:00
for node in self.topo.topo_builder.net:
2020-06-29 12:13:47 +00:00
for intf in self.topo.get_interface_names(node):
2020-06-29 10:46:07 +00:00
logging.info("Disable TSO on interface {}".format(intf))
cmd = "ethtool -K {} tso off".format(intf)
logging.info(cmd)
2020-06-29 12:13:47 +00:00
self.topo.command_to(node, cmd)
2020-06-26 09:17:00 +00:00
def run_netem_at(self):
"""
Prepare netem commands to be run after some delay
"""
2020-06-29 07:51:55 +00:00
if not self.topo.change_netem:
2020-06-26 09:17:00 +00:00
# Just rely on defaults of TCLink
2020-06-29 07:51:55 +00:00
logging.info("No need to change netem")
2020-06-26 09:17:00 +00:00
return
logging.info("Will change netem config on the fly")
2020-06-29 10:46:07 +00:00
for b in self.topo.bottleneck_links:
b.configure_changing_bottleneck()
2020-06-24 08:36:26 +00:00
def getMidLeftName(self, i):
"get Middle link, left box name"
pass
def getMidRightName(self, i):
pass
2020-06-29 07:51:55 +00:00
def configure_interfaces(self):
"""
Function to override to configure the interfaces of the topology
"""
2020-06-29 12:22:39 +00:00
for b in self.topo.bottleneck_links:
b.configure_bottleneck()
2020-06-29 07:51:55 +00:00
def configure_routing(self):
"""
Function to override to configure the routing of the topology
"""
2020-06-24 08:36:26 +00:00
pass
2020-06-26 09:17:00 +00:00
def client_interface_count(self):
"""
Return the number of client's interfaces
"""
raise NotImplementedError()
def get_client_interface(self, index):
"""
Return the client's interface with index `index`
"""
raise NotImplementedError()
def get_router_interface_to_switch(self, index):
"""
Return the router's interface to switch with index `index`
"""
raise NotImplementedError()
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def interface_backup_command(self, interface_name):
return "ip link set dev {} multipath backup ".format(
interface_name)
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def interface_up_command(self, interface_name, ip, subnet):
return "ifconfig {} {} netmask {}".format(interface_name, ip, subnet)
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def add_table_route_command(self, from_ip, id):
return "ip rule add from {} table {}".format(from_ip, id + 1)
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def add_link_scope_route_command(self, network, interface_name, id):
return "ip route add {} dev {} scope link table {}".format(
network, interface_name, id + 1)
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def add_table_default_route_command(self, via, id):
return "ip route add default via {} table {}".format(via, id + 1)
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def add_global_default_route_command(self, via, interface_name):
return "ip route add default scope global nexthop via {} dev {}".format(via, interface_name)
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def arp_command(self, ip, mac):
return "arp -s {} {}".format(ip, mac)
2020-06-24 08:36:26 +00:00
2020-06-29 07:51:55 +00:00
def add_simple_default_route_command(self, via):
return "ip route add default via {}".format(via)