6 #The following is not essential
7 #from soaplib.wsgi_soap import SimpleWSGISoapApp
8 #from soaplib.serializers.primitive import *
9 #from soaplib.serializers.clazz import *
11 from sfa.util.faults import *
12 from sfa.util.xrn import urn_to_hrn
13 from sfa.server.registry import Registries
14 from sfa.util.config import Config
15 from sfa.plc.nodes import *
16 from sfa.util.callids import Callids
18 # Message IDs for all the SFA light calls
19 # This will be used by the aggrMgr controller
20 SFA_GET_RESOURCES = 101
21 SFA_CREATE_SLICE = 102
24 SFA_DELETE_SLICE = 105
26 SFA_RESET_SLICES = 107
30 def print_buffer(buf):
31 for i in range(0,len(buf)):
35 # Shud we first obtain the message length?
36 # msg_len = socket.ntohs(sock.recv(2))
42 except socket.error, message:
43 if 'timed out' in message:
46 sys.exit("Socket error: " + message)
52 print 'Done extracting %d bytes of response from aggrMgr' % len(msg)
55 def connect(server, port):
56 '''Connect to the Aggregate Manager module'''
57 sock = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
58 sock.connect ( ( server, port) )
60 if DEBUG: print 'Connected!'
63 def connect_aggrMgr():
64 (aggr_mgr_ip, aggr_mgr_port) = Config().get_openflow_aggrMgr_info()
65 if DEBUG: print """Connecting to port %d of %s""" % (aggr_mgr_port, aggr_mgr_ip)
66 return connect(aggr_mgr_ip, aggr_mgr_port)
68 def generate_slide_id(cred, hrn):
73 #return cred + '_' + hrn
76 def msg_aggrMgr(cred, hrn, msg_id):
77 slice_id = generate_slide_id(cred, hrn)
79 msg = struct.pack('> B%ds' % len(slice_id), msg_id, slice_id)
80 buf = struct.pack('> H', len(msg)+2) + msg
83 aggrMgr_sock = connect_aggrMgr()
84 aggrMgr_sock.send(buf)
87 except socket.error, message:
89 except IOerror, message:
93 def start_slice(cred, xrn):
94 hrn = urn_to_hrn(xrn)[0]
95 if DEBUG: print "Received start_slice call"
96 return msg_aggrMgr(SFA_START_SLICE)
98 def stop_slice(cred, xrn):
99 hrn = urn_to_hrn(xrn)[0]
100 if DEBUG: print "Received stop_slice call"
101 return msg_aggrMgr(SFA_STOP_SLICE)
103 def DeleteSliver(cred, xrn, call_id):
104 if Callids().already_handled(call_id): return ""
105 hrn = urn_to_hrn(xrn)[0]
106 if DEBUG: print "Received DeleteSliver call"
107 return msg_aggrMgr(SFA_DELETE_SLICE)
109 def reset_slices(cred, xrn):
110 hrn = urn_to_hrn(xrn)[0]
111 if DEBUG: print "Received reset_slices call"
112 return msg_aggrMgr(SFA_RESET_SLICES)
114 ### Thierry: xxx this should ahve api as a first arg - probably outdated
115 def CreateSliver(cred, xrn, rspec, call_id):
116 if Callids().already_handled(call_id): return ""
118 hrn = urn_to_hrn(xrn)[0]
119 if DEBUG: print "Received CreateSliver call"
120 slice_id = generate_slide_id(cred, hrn)
122 msg = struct.pack('> B%ds%ds' % (len(slice_id)+1, len(rspec)), SFA_CREATE_SLICE, slice_id, rspec)
123 buf = struct.pack('> H', len(msg)+2) + msg
126 aggrMgr_sock = connect_aggrMgr()
127 aggrMgr_sock.send(buf)
128 if DEBUG: print "Sent %d bytes and closing connection" % len(buf)
131 if DEBUG: print "----------------"
133 except socket.error, message:
135 except IOerror, message:
139 # Thierry : xxx this would need to handle call_id like the other AMs but is outdated...
140 def ListResources(cred, xrn=None):
141 hrn = urn_to_hrn(xrn)[0]
142 if DEBUG: print "Received ListResources call"
143 slice_id = generate_slide_id(cred, hrn)
145 msg = struct.pack('> B%ds' % len(slice_id), SFA_GET_RESOURCES, slice_id)
146 buf = struct.pack('> H', len(msg)+2) + msg
149 aggrMgr_sock = connect_aggrMgr()
150 aggrMgr_sock.send(buf)
151 resource_list = extract(aggrMgr_sock);
154 if DEBUG: print "----------------"
156 except socket.error, message:
158 except IOerror, message:
163 Returns the request context required by sfatables. At some point, this mechanism should be changed
164 to refer to "contexts", which is the information that sfatables is requesting. But for now, we just
165 return the basic information needed in a dict.
167 def fetch_context(slice_hrn, user_hrn, contexts):
168 base_context = {'sfa':{'user':{'hrn':user_hrn}}}
173 r.parseFile(sys.argv[1])
175 CreateSliver(None,'plc',rspec,'call-id-plc')
177 if __name__ == "__main__":