2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 from nepi.execution.attribute import Attribute, Flags
20 from nepi.execution.resource import clsinit_copy
21 from nepi.execution.trace import Trace
22 from nepi.resources.ns3.ns3base import NS3Base
25 class NS3Route(NS3Base):
29 def _register_attributes(cls):
30 network = Attribute("network", "Destination network address",
33 prefix = Attribute("prefix", "Network prefix for the network",
36 nexthop = Attribute("nexthop", "Address of next hop in the route",
39 cls._register_attribute(network)
40 cls._register_attribute(prefix)
41 cls._register_attribute(nexthop)
43 def __init__(self, ec, guid):
44 super(NS3Route, self).__init__(ec, guid)
48 from nepi.resources.ns3.ns3node import NS3BaseNode
49 nodes = self.get_connected(NS3BaseNode.get_rtype())
52 msg = "Device not connected to node"
54 raise RuntimeError(msg)
59 def _rms_to_wait(self):
60 # Wait for all network devices connected to the node to be ready
61 # before configuring the routes, else the route might refer to a
62 # non yet existing interface
65 rms.update(self.node.devices)
68 def _instantiate_object(self):
71 def _configure_object(self):
72 network = self.get("network")
73 prefix = self.get("prefix")
74 nexthop = self.get("nexthop")
75 ipv4_uuid = self.node.ipv4.uuid
77 ret = self.simulation.invoke(ipv4_uuid, "addStaticRoute", network,
81 msg = "Could not configure route %s/%s hop: %s" % (network, prefix,
84 raise RuntimeError(msg)
86 def _connect_object(self):
88 if node and node.uuid not in self.connected:
89 self._connected.add(node.uuid)