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
27 class NS3Route(NS3Base):
31 def _register_attributes(cls):
32 network = Attribute("network", "Destination network address",
35 prefix = Attribute("prefix", "Network prefix for the network",
38 nexthop = Attribute("nexthop", "Address of next hop in the route",
41 cls._register_attribute(network)
42 cls._register_attribute(prefix)
43 cls._register_attribute(nexthop)
45 def __init__(self, ec, guid):
46 super(NS3Route, self).__init__(ec, guid)
50 from nepi.resources.ns3.ns3node import NS3BaseNode
51 nodes = self.get_connected(NS3BaseNode.get_rtype())
54 msg = "Device not connected to node"
56 raise RuntimeError(msg)
61 def _rms_to_wait(self):
62 # Wait for all network devices connected to the node to be ready
63 # before configuring the routes, else the route might refer to a
64 # non yet existing interface
67 rms.update(self.node.devices)
70 def _instantiate_object(self):
73 def _configure_object(self):
74 network = self.get("network")
75 prefix = self.get("prefix")
76 nexthop = self.get("nexthop")
77 ipv4_uuid = self.node.ipv4.uuid
79 ret = self.simulation.invoke(ipv4_uuid, "addStaticRoute", network,
83 msg = "Could not configure route %s/%s hop: %s" % (network, prefix,
86 raise RuntimeError(msg)
88 def _connect_object(self):
90 if node and node.uuid not in self.connected:
91 self._connected.add(node.uuid)