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 as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.attribute import Attribute, Flags
21 from nepi.execution.resource import clsinit_copy
22 from nepi.execution.trace import Trace
23 from nepi.resources.ns3.ns3base import NS3Base
28 class NS3Route(NS3Base):
32 def _register_attributes(cls):
33 network = Attribute("network", "Destination network address",
36 prefix = Attribute("prefix", "Network prefix for the network",
39 nexthop = Attribute("nexthop", "Address of next hop in the route",
42 cls._register_attribute(network)
43 cls._register_attribute(prefix)
44 cls._register_attribute(nexthop)
46 def __init__(self, ec, guid):
47 super(NS3Route, self).__init__(ec, guid)
51 from nepi.resources.ns3.ns3node import NS3BaseNode
52 nodes = self.get_connected(NS3BaseNode.get_rtype())
55 msg = "Device not connected to node"
57 raise RuntimeError, msg
62 def _rms_to_wait(self):
63 # Wait for all network devices connected to the node to be ready
64 # before configuring the routes, else the route might refer to a
65 # non yet existing interface
68 rms.update(self.node.devices)
71 def _instantiate_object(self):
74 def _configure_object(self):
75 network = self.get("network")
76 prefix = self.get("prefix")
77 nexthop = self.get("nexthop")
78 ipv4_uuid = self.node.ipv4.uuid
80 ret = self.simulation.invoke(ipv4_uuid, "addStaticRoute", network,
84 msg = "Could not configure route %s/%s hop: %s" % (network, prefix,
87 raise RuntimeError, msg
89 def _connect_object(self):
91 if node and node.uuid not in self.connected:
92 self._connected.add(node.uuid)