1 from sfa.util.faults import *
2 from sfa.util.misc import *
3 from sfa.util.rspec import Rspec
4 from sfa.server.registry import Registries
5 from sfa.plc.nodes import *
8 # Probably the following is not essential
9 #from soaplib.wsgi_soap import SimpleWSGISoapApp
10 #from soaplib.serializers.primitive import *
11 #from soaplib.serializers.clazz import *
16 SOAP_INTERFACE_PORT = 7889
17 AGGREGATE_MANAGER_PORT = 2603
18 AGGREGATE_MANAGER_IP = 'localhost'
19 #AGGREGATE_MANAGER_IP = 'openflowvisor.stanford.edu'
21 # Message IDs for all the GENI light calls
22 # This will be used by the aggrMgr controller
23 SFA_GET_RESOURCES = 101
24 SFA_CREATE_SLICE = 102
27 SFA_DELETE_SLICE = 105
29 SFA_RESET_SLICES = 107
33 def print_buffer(buf):
34 for i in range(0,len(buf)):
38 # Shud we first obtain the message length?
39 # msg_len = socket.ntohs(sock.recv(2))
45 except socket.error, message:
46 if 'timed out' in message:
49 sys.exit("Socket error: " + message)
55 print 'done extracting response from aggrMgr'
58 def connect(server, port):
59 '''Connect to the Aggregate Manager module'''
60 sock = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
61 sock.connect ( ( server, port) )
63 print 'connected to aggregate manager module'
66 def connect_aggrMgr():
67 return connect(AGGREGATE_MANAGER_IP, AGGREGATE_MANAGER_PORT)
69 def generate_slide_id(cred, hrn):
74 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 socketerror, message:
89 except IOerror, message:
93 def start_slice(cred, hrn):
94 if DEBUG: print "Received start_slice call"
95 return msg_aggrMgr(SFA_START_SLICE)
97 def stop_slice(cred, hrn):
98 if DEBUG: print "Received stop_slice call"
99 return msg_aggrMgr(SFA_STOP_SLICE)
101 def delete_slice(cred, hrn):
102 if DEBUG: print "Received delete_slice call"
103 return msg_aggrMgr(SFA_DELETE_SLICE)
105 def reset_slices(cred, hrn):
106 if DEBUG: print "Received reset_slices call"
107 return msg_aggrMgr(SFA_RESET_SLICES)
109 def create_slice(cred, hrn, rspec):
110 if DEBUG: print "Received create_slice call"
111 slice_id = generate_slide_id(cred, hrn)
113 msg = struct.pack('> B%ds%ds' % len(slice_id), SFA_CREATE_SLICE, slice_id, rspec)
114 buf = struct.pack('> H', len(msg)+2) + msg
117 aggrMgr_sock = connect_aggrMgr()
118 aggrMgr_sock.send(buf)
121 except socketerror, message:
123 except IOerror, message:
127 def get_resources(cred, hrn=None):
128 if DEBUG: print "Received get_resources call"
129 slice_id = generate_slide_id(cred, hrn)
131 msg = struct.pack('> B%ds' % len(slice_id), SFA_GET_RESOURCES, slice_id)
132 buf = struct.pack('> H', len(msg)+2) + msg
135 aggrMgr_sock = connect_aggrMgr()
136 aggrMgr_sock.send(buf)
137 resource_list = extract(aggrMgr_sock);
141 except socketerror, message:
143 except IOerror, message:
147 def fetch_context(slice_hrn, user_hrn, contexts):
152 r.parseFile(sys.argv[1])
154 create_slice(None,'plc',rspec)
156 if __name__ == "__main__":