blob: a8bfe7fe9c98f0afe3cf61f446167137175624a8 [file] [log] [blame]
Zsolt Haraszti023ea7c2016-10-16 19:30:34 -07001#!/usr/bin/env python
2#
3# Copyright 2016 the original author or authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18"""TODO This is a POC placeholder """
19import grpc
20from twisted.internet import reactor
21
22from agent import Agent
23from protos import voltha_pb2
24
25from grpc_client import GrpcClient
26
27
28if __name__ == '__main__':
29
30 # Create grpc channel to Voltha and grab client stub
31 channel = grpc.insecure_channel('localhost:50055')
32
33 # Connect to voltha using grpc and fetch the list of logical devices
34 stub = voltha_pb2.VolthaLogicalLayerStub(channel)
35 devices = stub.ListLogicalDevices(voltha_pb2.NullMessage()).items
36 print 'device id and datapaht_id list:'
37 for device in devices:
38 print '\t{} -> {}'.format(device.id, device.datapath_id)
39
40 # make a device.datapath_id -> device.id map (this will need to be actively
41 # managed in the real agent based on devices coming and going
42 device_id_map = dict((device.datapath_id, device.id) for device in devices)
43
44 # Create shared gRPC API object
45 grpc_client = GrpcClient(channel, device_id_map)
46
47 # Instantiate an OpenFlow agent for each logical device
48 agents = [
49 Agent('localhost:6633', device.datapath_id, grpc_client).run()
50 for device in devices
51 ]
52
53 def shutdown():
54 [a.stop() for a in agents]
55
56 reactor.addSystemEventTrigger('before', 'shutdown', shutdown)
57 reactor.run()