blob: 358b72894312ae0d3fe1757f7e31e0b96c8e3769 [file] [log] [blame]
Zsolt Harasztie3ece3c2016-12-19 23:32:38 -08001#!/usr/bin/env python
2
3import sys
4from time import sleep
5
6from scapy.packet import Packet
7from twisted.spread import pb
8from twisted.internet import reactor
9from twisted.internet.defer import inlineCallbacks, returnValue, DeferredQueue
10from twisted.python import util
11
12from common.frameio.frameio import hexify
13from common.utils.asleep import asleep
14from voltha.extensions.omci.omci import *
15
16
17class OmciProxy(pb.Root):
18
19 def __init__(self):
20 reactor.listenTCP(24497, pb.PBServerFactory(self))
21 self.remote = None
22 self.response_queue = DeferredQueue()
23
24 @inlineCallbacks
25 def connect(self):
26 factory = pb.PBClientFactory()
27 reactor.connectTCP("10.111.101.206", 24498, factory)
28 self.remote = yield factory.getRootObject()
29 print 'connected'
30 yield self.remote.callRemote("setRemote", port=24496)
31
32 def remote_echo(self, pkt_type, pon, onu, port, crc, size, data):
33 print "Packet Type:", pkt_type
34 print "PON:", pon
35 print "ONU ID:", onu
36 print "Port:", port
37 print "CRC OK:", crc
38 print "Packet Size:", size
39 print "received:", hexify(data)
40 self.response_queue.put(data)
41
42 @inlineCallbacks
43 def send_omci(self, msg):
44 if isinstance(msg, Packet):
45 msg = str(msg)
46 try:
47 print ' sending:', msg
48 yield self.remote.callRemote("send_omci", 0, 0, 1, msg)
49 print 'msg sent'
50
51 except Exception, e:
52 print >> sys.stderr, 'Blew up:', str(e)
53
54 def receive(self):
55 return self.response_queue.get()
56
57
58@inlineCallbacks
59def chat():
60 proxy = OmciProxy()
61 yield proxy.connect()
62
63 tx_id = [0]
64 def get_tx_id():
65 tx_id[0] += 1
66 return tx_id[0]
67
68 if 0:
69 # MIB RESET
70 frame = OmciFrame(
71 transaction_id=get_tx_id(),
72 message_type=OmciMibReset.message_id,
73 omci_message=OmciMibReset(
74 entity_class=OntData.class_id
75 )
76 )
77 yield proxy.send_omci(hexify(str(frame)))
78
79 # MIB RESET RESPONSE
80 response = yield proxy.receive()
81 resp = OmciFrame(response)
82 resp.show()
83
84 if 0:
85 # GET ALL ALARMS
86 frame = OmciFrame(
87 transaction_id=get_tx_id(),
88 message_type=OmciGetAllAlarms.message_id,
89 omci_message=OmciGetAllAlarms(
90 entity_class=OntData.class_id,
91 entity_id=0
92 )
93 )
94 yield proxy.send_omci(hexify(str(frame)))
95
96 # MIB UPLOAD RESPONSE
97 response = yield proxy.receive()
98 resp = OmciFrame(response)
99 resp.show()
100
101 if 0:
102 # MIB UPLOAD
103 frame = OmciFrame(
104 transaction_id=get_tx_id(),
105 message_type=OmciMibUpload.message_id,
106 omci_message=OmciMibUpload(
107 entity_class=OntData.class_id
108 )
109 )
110 yield proxy.send_omci(hexify(str(frame)))
111
112 # MIB UPLOAD RESPONSE
113 response = yield proxy.receive()
114 resp = OmciFrame(response)
115 resp.show()
116
117 n_commands = resp.omci_message.number_of_commands
118 for seq_num in range(n_commands):
119 print 'seq_num', seq_num
120 frame = OmciFrame(
121 transaction_id=get_tx_id(),
122 message_type=OmciMibUploadNext.message_id,
123 omci_message=OmciMibUploadNext(
124 entity_class=OntData.class_id,
125 command_sequence_number=seq_num
126 )
127 )
128 yield proxy.send_omci(hexify(str(frame)))
129
130 response = yield proxy.receive()
131 print hexify(response)
132 # resp = OmciFrame(response)
133 # resp.show()
134
135
136 if 1:
137 # GET CIRCUIT PACK
138 frame = OmciFrame(
139 transaction_id=get_tx_id(),
140 message_type=OmciGet.message_id,
141 omci_message=OmciGet(
142 entity_class=CircuitPack.class_id,
143 entity_id=0x101,
144 attributes_mask=CircuitPack.mask_for('vendor_id')
145 )
146 )
147 yield proxy.send_omci(hexify(str(frame)))
148
149 # MIB UPLOAD RESPONSE
150 response = yield proxy.receive()
151 resp = OmciFrame(response)
152 resp.show()
153
154 yield asleep(1)
155 reactor.stop()
156
157
158if __name__ == '__main__':
159 reactor.callLater(0, chat)
160 reactor.run()