Changing reschedule_delay internals
[nepi.git] / src / nepi / resources / linux / ns3 / ccn / ns3fibentrydceapplication.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2014 INRIA
4 #
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.
9 #
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.
14 #
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/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy, ResourceState
22 from nepi.resources.linux.ns3.ccn.ns3ccndceapplication import LinuxNS3CCNDceApplication
23
24 @clsinit_copy
25 class LinuxNS3DceFIBEntry(LinuxNS3CCNDceApplication):
26     _rtype = "ns3::LinuxDceFIBEntry"
27
28     @classmethod
29     def _register_attributes(cls):
30         uri = Attribute("uri",
31                 "URI prefix to match and route for this FIB entry",
32                 default = "ccnx:/",
33                 flags = Flags.Design)
34
35         protocol = Attribute("protocol",
36                 "Transport protocol used in network connection to peer "
37                 "for this FIB entry. One of 'udp' or 'tcp'.",
38                 type = Types.Enumerate, 
39                 default = "udp",
40                 allowed = ["udp", "tcp"],
41                 flags = Flags.Design)
42
43         host = Attribute("host",
44                 "Peer hostname used in network connection for this FIB entry. ",
45                 flags = Flags.Design)
46
47         port = Attribute("port",
48                 "Peer port address used in network connection to peer "
49                 "for this FIB entry.",
50                 flags = Flags.Design)
51
52         ip = Attribute("ip",
53                 "Peer host public IP used in network connection for this FIB entry. ",
54                 flags = Flags.Design)
55
56         home = Attribute("home", "Sets HOME environmental variable. ",
57                 default = "/root",
58             flags = Flags.Design)
59  
60         cls._register_attribute(uri)
61         cls._register_attribute(protocol)
62         cls._register_attribute(host)
63         cls._register_attribute(port)
64         cls._register_attribute(ip)
65         cls._register_attribute(home)
66
67     def _instantiate_object(self):
68         if not self.get("binary"):
69             self.set("binary", "ccndc")
70             
71         if not self.get("arguments"):
72             self.set("arguments", self._arguments)
73
74         if not self.get("environment"):
75             self.set("environment", self._environment)
76         
77         super(LinuxNS3DceFIBEntry, self)._instantiate_object()
78
79     @property
80     def _environment(self):
81         envs = dict({
82             "home": "HOME",
83             })
84
85         env = ";".join(map(lambda k: "%s=%s" % (envs.get(k), str(self.get(k))), 
86             [k for k in envs.keys() if self.get(k)]))
87
88         return env
89
90     @property
91     def _arguments(self):
92         args = ["-v", "add"]
93
94         if self.get("uri"):
95             args.append(self.get("uri"))
96         if self.get("protocol"):
97             args.append(self.get("protocol"))
98         if self.get("host"):
99             args.append(self.get("host"))
100         if self.get("port"):
101             args.append(self.get("port"))
102         if self.get("ip"):
103             args.append(self.get("ip"))
104
105         return ";".join(args) 
106
107