af5eeadd8eeb4beabd7ccc3596d35e6c59d070ce
[nepi.git] / src / nepi / testbeds / netns / __init__.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 from nepi.core import description 
4 from nepi.core.attributes import Attribute
5 from nepi.util import validation
6
7 TESTBED_ID = "netns"
8
9 factories_metadata = dict({
10     "v0.1" : metadata_v01
11     })
12
13 def metadata_v01():
14     return = dict({
15              "node": dict({ #TODO: RoutingTable
16                     "display_name": "Node",
17                     "help": "Node element",
18                     "category": "topology",
19                     "connector_types": [
20                         ("netns_node_apps", 
21                             "Connector from node to applications", 
22                             "apps", -1, 0,
23                             ["netns_application_node"]),
24                         ("netns_node_devs", 
25                             "Connector from node to network interfaces", 
26                             "devs", -1, 0,
27                             [   
28                                 "netns_nodeiface_node", 
29                                 "netns_tapiface_node", 
30                                 "netns_p2piface_node"
31                             ])
32                         ],
33                     "element_attributes": [
34                         ("forward_X11", 
35                             "Forward x11 from main namespace to the node", 
36                             Attribute.BOOL, 
37                             False, None, None, False, 
38                             validation.is_bool)
39                         ]
40                 }),
41             "p2piface": dict({ #TODO: Addresses!
42                     "display_name": "P2PInterface",
43                     "help": "Point to point network interface",
44                     "category": "devices",
45                     "connector_types": [
46                             ("netns_p2piface_node", 
47                                 "Connector from P2PInterface to Node", 
48                                 "node", 1, 1, 
49                                 ["netns_node_devs"]),
50                             ("netns_p2pinterface_p2p", 
51                                 "Connector to another P2PInterface", 
52                                 "p2p", 1, 0, 
53                                 ["netns_p2piface_p2p"])
54                         ],
55                     "element_attributes": [
56                         ("lladdr", "Mac address", Attribute.STRING, 
57                             None, None, None, False, 
58                             validation.is_mac_address),
59                         ("up", "Link up", Attribute.BOOL, 
60                             False, None, None, False, 
61                             validation.is_bool),
62                         ("name", "Device name", Attribute.STRING, 
63                             None, None, None, False, 
64                             validation.is_string),
65                         ("mtu", "Maximmum transmition unit for device", 
66                             Attribute.INTEGER,
67                             None, None, None, False, 
68                             validation.is_integer),
69                         ("broadcast", "Broadcast address", 
70                             Attribute.STRING, 
71                             None, None, None, False, 
72                             validation.is_string),
73                         ("multicast", "Is multicast enabled", 
74                             Attribute.BOOL, 
75                             False, None, None, False, 
76                             validation.is_bool),
77                         ("arp", "Is ARP enabled", Attribute.BOOL, 
78                             True, None, None, False, 
79                             validation.is_bool),
80                     ]
81                 }),
82                 "tapiface": dict({ #TODO: Addresses!
83                     "display_name": "TapNodeInterface",
84                     "help": "Tap device network interface",
85                     "category": "devices",
86                     "connector_types": [
87                         ("netns_tapiface_node", 
88                             "Connector to a Node", 
89                             "node", 1, 1, 
90                             ["netns_node_devs"]),
91                        ("netns_tapiface_fd", 
92                            "Connector to a network interface that can receive a file descriptor", 
93                            "fd", 1, 0, 
94                             # TODO: Doesn't exist yet!
95                            ["ns3_fdnetdev_fd"])
96                        ],
97                     "element_attributes": [
98                         ("lladdr", "Mac address", Attribute.STRING, 
99                             None, None, None, False, 
100                             validation.is_mac_address),
101                         ("up", "Link up", Attribute.BOOL, 
102                             False, None, None, False, 
103                             validation.is_bool),
104                         ("name", "Device name", Attribute.STRING, 
105                             None, None, None, False, 
106                             validation.is_string),
107                         ("mtu", "Maximmum transmition unit for device", 
108                             Attribute.INTEGER, 
109                             None, None, None, False, 
110                             validation.is_integer),
111                         ("broadcast", "Broadcast address", 
112                             Attribute.STRING, 
113                             None, None, None, False, 
114                             validation.is_string),
115                         ("multicast", "Is multicast enabled", 
116                             Attribute.BOOL, 
117                             False, None, None, False, 
118                             validation.is_bool),
119                         ("arp", "Is ARP enabled", Attribute.BOOL, 
120                             True, None, None, False, 
121                             validation.is_bool),
122                     ]
123                 }),
124             "nodeiface": dict({ #TODO: Addresses!
125                     "display_name": "NodeInterface",
126                     "help": "Node network interface",
127                     "category": "devices",
128                     "connector_types": [
129                         ("netns_nodeiface_node", "Connector to a node",
130                             "node", 1, 1, 
131                             ["netns_node_devs"]),
132                         ("netns_nodeiface_switch", "Connector to a switch", 
133                             "switch", 1, 0,
134                             ["netns_switch_devs"])
135                         ],
136                     "element_attributes": [
137                         ("lladdr", "Mac address", Attribute.STRING, 
138                             None, None, None, False, 
139                             validation.is_mac_address),
140                         ("up", "Link up", Attribute.BOOL, 
141                             False, None, None, False, 
142                             validation.is_bool),
143                         ("name", "Device name", Attribute.STRING, 
144                             None, None, None, False, 
145                             validation.is_string),
146                         ("mtu", "Maximmum transmition unit for device", 
147                             Attribute.INTEGER, 
148                             None, None, None, False, 
149                             validation.is_integer),
150                         ("broadcast", "Broadcast address", 
151                             Attribute.STRING,
152                             None, None, None, False, 
153                             validation.is_string),
154                         ("multicast", "Is multicast enabled", 
155                             Attribute.BOOL, 
156                             False, None, None, False, 
157                             validation.is_bool),
158                         ("arp", "Is ARP enabled", Attribute.BOOL, 
159                             True, None, None, False, 
160                             validation.is_bool),
161                     ]
162                 }),
163             "switch": dict({
164                     "display_name": "Switch",
165                     "help": "Switch interface",
166                     "category": "devices",
167                     "connector_types": [
168                         ("netns_switch_devs", "Connector to network interfaces", 
169                             "devs", -1, 0, 
170                             ["netns_nodeiface_switch"])
171                         ],
172                     "element_attributes": [
173                         ("Up", "Link up", Attribute.BOOL, 
174                             False, None, None, False,
175                             validation.is_bool),
176                         ("Name", "Device name", Attribute.STRING, 
177                             None, None, None, False,
178                             validation,is_string),
179                         ("Mtu", "Maximmum transmition unit for device", 
180                             Attribute.INTEGER, 
181                             None, None, None, False,
182                             validation.is_integer),
183                         ("Multicast", "Is multicast enabled", 
184                             Attribute.BOOL,
185                             None, None, None, False, 
186                             validation.is_bool),
187                         #TODO:("Stp", help, type, value, range, allowed, readonly, validation_function),
188                         #TODO:("ForwarddDelay", help, type, value, range, allowed, readonly, validation_function),
189                         #TODO:("HelloTime", help, type, value, range, allowed, readonly, validation_function),
190                         #TODO:("AgeingTime", help, type, value, range, allowed, readonly, validation_function),
191                         #TODO:("MaxAge", help, type, value, range, allowed, readonly, validation_function)
192                         ]
193                 }),
194                 "application": dict({
195                     "display_name": "Application",
196                     "help": "Generic executable command line application",
197                     "category": "applications",
198                     "connector_types": [
199                             ("netns_application_node", "Connector to a node",
200                                 "node", 1, 1, 
201                                 ["netns_node_apps"])
202                         ],
203                     "traces": [
204                             ("StdoutTrace", "Standard output"),
205                             ("StderrTrace", "Standard error")
206                         ],
207                     "element_attributes": [
208                         ("Command", "Command line",
209                             Attribute.STRING,
210                             None, None, None, False,
211                             validation.is_string)
212                         ("User", "System user", 
213                             Attribute.STRING, 
214                             None, None, None, False,
215                             validation.is_string)
216                         ("Stdin", "Standard input", 
217                             Attribute.STRING,
218                             None, None, None, False,
219                             validation.is_string)
220                         ]
221                 }),
222
223         })
224
225 def create_factories(version):
226     factories = list()
227     metadata = factories_metadata[version]()
228     
229     for factory_id, info in metadata.iteritems():
230         help = info["help"]
231         category = info["category"]
232         display_name = info["display_name"]
233         factory = Factory(factory_id, display_name, help, category)
234
235         for (connector_type_id, help, name, max, min, 
236                 allowed_connector_type_ids) in info["connector_types"]:
237             factory.add_connector_type(connector_type_id, help, name, max,
238                     min, allowed_connector_type_ids)
239         for :
240             factory.add_trace(name, help)
241         for :
242             factory.add_attribute(name, help, type, value, range, allowed,
243                     readonly, validation_function)
244          for :
245             factory.add_element_attribute(name, help, type, value, range,
246                     allowed, readonly, validation_function)
247         factories.append(factory)
248     return factories
249
250 def create_provider(version):
251     provider = description.FactoriesProvider()
252     for factory in create_factories(version):
253         provider.add_factory(factory)
254     return provider
255
256 def create_description_instance(guid_generator, version, provider):
257     return description.TestbedDescription(guid_generator, TESTBED_ID, version, provider)
258
259