63e5d19a6bdb82115f4f413603b335897713e4f2
[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, reschedule_delay
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         cls._register_attribute(uri)
57         cls._register_attribute(protocol)
58         cls._register_attribute(host)
59         cls._register_attribute(port)
60         cls._register_attribute(ip)
61
62     def _instantiate_object(self):
63         if not self.get("binary"):
64             self.set("binary", "ccndc")
65             
66         if not self.get("arguments"):
67             self.set("arguments", self._arguments)
68
69         super(LinuxNS3DceFIBEntry, self)._instantiate_object()
70
71     @property
72     def _arguments(self):
73         args = ["-v", "add"]
74
75         if self.get("uri"):
76             args.append(self.get("uri"))
77         if self.get("protocol"):
78             args.append(self.get("protocol"))
79         if self.get("host"):
80             args.append(self.get("host"))
81         if self.get("port"):
82             args.append(self.get("port"))
83         if self.get("ip"):
84             args.append(self.get("ip"))
85
86         return ";".join(args) 
87
88