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.util.config import Config
6 from sfa.plc.nodes import *
9 #The following is not essential
10 #from soaplib.wsgi_soap import SimpleWSGISoapApp
11 #from soaplib.serializers.primitive import *
12 #from soaplib.serializers.clazz import *
17 # Message IDs for all the GENI light calls
18 # This will be used by the aggrMgr controller
19 SFA_GET_RESOURCES = 101
20 SFA_CREATE_SLICE = 102
23 SFA_DELETE_SLICE = 105
25 SFA_RESET_SLICES = 107
29 def print_buffer(buf):
30 for i in range(0,len(buf)):
34 # Shud we first obtain the message length?
35 # msg_len = socket.ntohs(sock.recv(2))
41 except socket.error, message:
42 if 'timed out' in message:
45 sys.exit("Socket error: " + message)
51 print 'Done extracting %d bytes of response from aggrMgr' % len(msg)
54 def connect(server, port):
55 '''Connect to the Aggregate Manager module'''
56 sock = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
57 sock.connect ( ( server, port) )
59 if DEBUG: print 'Connected!'
62 def connect_aggrMgr():
63 (aggr_mgr_ip, aggr_mgr_port) = Config().get_openflow_aggrMgr_info()
64 if DEBUG: print """Connecting to port %d of %s""" % (aggr_mgr_port, aggr_mgr_ip)
65 return connect(aggr_mgr_ip, aggr_mgr_port)
67 def generate_slide_id(cred, hrn):
72 #return cred + '_' + hrn
75 def msg_aggrMgr(cred, hrn, msg_id):
76 slice_id = generate_slide_id(cred, hrn)
78 msg = struct.pack('> B%ds' % len(slice_id), msg_id, slice_id)
79 buf = struct.pack('> H', len(msg)+2) + msg
82 aggrMgr_sock = connect_aggrMgr()
83 aggrMgr_sock.send(buf)
86 except socket.error, message:
88 except IOerror, message:
92 def start_slice(cred, hrn):
93 if DEBUG: print "Received start_slice call"
94 return msg_aggrMgr(SFA_START_SLICE)
96 def stop_slice(cred, hrn):
97 if DEBUG: print "Received stop_slice call"
98 return msg_aggrMgr(SFA_STOP_SLICE)
100 def delete_slice(cred, hrn):
101 if DEBUG: print "Received delete_slice call"
102 return msg_aggrMgr(SFA_DELETE_SLICE)
104 def reset_slices(cred, hrn):
105 if DEBUG: print "Received reset_slices call"
106 return msg_aggrMgr(SFA_RESET_SLICES)
108 def create_slice(cred, hrn, rspec):
109 if DEBUG: print "Received create_slice call"
110 slice_id = generate_slide_id(cred, hrn)
112 msg = struct.pack('> B%ds%ds' % (len(slice_id)+1, len(rspec)), SFA_CREATE_SLICE, slice_id, rspec)
113 buf = struct.pack('> H', len(msg)+2) + msg
116 aggrMgr_sock = connect_aggrMgr()
117 aggrMgr_sock.send(buf)
118 if DEBUG: print "Sent %d bytes and closing connection" % len(buf)
121 if DEBUG: print "----------------"
123 except socket.error, message:
125 except IOerror, message:
129 def get_rspec(cred, hrn=None):
130 if DEBUG: print "Received get_rspec call"
131 slice_id = generate_slide_id(cred, hrn)
133 msg = struct.pack('> B%ds' % len(slice_id), SFA_GET_RESOURCES, slice_id)
134 buf = struct.pack('> H', len(msg)+2) + msg
137 aggrMgr_sock = connect_aggrMgr()
138 aggrMgr_sock.send(buf)
139 resource_list = extract(aggrMgr_sock);
142 if DEBUG: print "----------------"
144 except socket.error, message:
146 except IOerror, message:
150 def fetch_context(slice_hrn, user_hrn, contexts):
155 r.parseFile(sys.argv[1])
157 create_slice(None,'plc',rspec)
159 if __name__ == "__main__":