blob: 67f78694d7ce60f18cd0ae9ffcee8174f0bf70d9 [file] [log] [blame]
khenaidoob9203542018-09-17 22:56:37 -04001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
khenaidoo6fdf0ba2018-11-02 14:38:33 -040018This facade handles kafka-formatted messages from the Core, extracts the kafka
19formatting and forwards the request to the concrete handler.
khenaidoob9203542018-09-17 22:56:37 -040020"""
khenaidoob9203542018-09-17 22:56:37 -040021
khenaidoo6fdf0ba2018-11-02 14:38:33 -040022from twisted.internet.defer import inlineCallbacks
khenaidoob9203542018-09-17 22:56:37 -040023from zope.interface import implementer
24
khenaidoob9203542018-09-17 22:56:37 -040025from adapters.interface import IAdapterInterface
khenaidoo6fdf0ba2018-11-02 14:38:33 -040026from adapters.protos.core_adapter_pb2 import IntType, InterAdapterMessage
khenaidoob9203542018-09-17 22:56:37 -040027from adapters.protos.device_pb2 import Device
khenaidoo6fdf0ba2018-11-02 14:38:33 -040028from adapters.protos.openflow_13_pb2 import FlowChanges, FlowGroups, Flows, \
29 FlowGroupChanges
khenaidoob9203542018-09-17 22:56:37 -040030
31
32class MacAddressError(BaseException):
33 def __init__(self, error):
34 self.error = error
35
36
37class IDError(BaseException):
38 def __init__(self, error):
39 self.error = error
40
41
42@implementer(IAdapterInterface)
43class AdapterRequestFacade(object):
44 """
45 Gate-keeper between CORE and device adapters.
46
47 On one side it interacts with Core's internal model and update/dispatch
48 mechanisms.
49
50 On the other side, it interacts with the adapters standard interface as
51 defined in
52 """
53
54 def __init__(self, adapter):
55 self.adapter = adapter
56
57 @inlineCallbacks
58 def start(self):
59 self.log.debug('starting')
60
61 @inlineCallbacks
62 def stop(self):
63 self.log.debug('stopping')
64
65 def adopt_device(self, device):
66 d = Device()
67 if device:
68 device.Unpack(d)
khenaidoo92e62c52018-10-03 14:02:54 -040069 return True, self.adapter.adopt_device(d)
khenaidoob9203542018-09-17 22:56:37 -040070 else:
khenaidoo92e62c52018-10-03 14:02:54 -040071 return False, d
khenaidoob9203542018-09-17 22:56:37 -040072
73 def get_ofp_device_info(self, device):
74 d = Device()
75 if device:
76 device.Unpack(d)
khenaidoo92e62c52018-10-03 14:02:54 -040077 return True, self.adapter.get_ofp_device_info(d)
khenaidoob9203542018-09-17 22:56:37 -040078 else:
khenaidoo92e62c52018-10-03 14:02:54 -040079 return False, d
khenaidoob9203542018-09-17 22:56:37 -040080
81 def get_ofp_port_info(self, device, port_no):
82 d = Device()
83 if device:
84 device.Unpack(d)
85 else:
86 return (False, d)
87
88 p = IntType()
89 port_no.Unpack(p)
90
khenaidoo92e62c52018-10-03 14:02:54 -040091 return True, self.adapter.get_ofp_port_info(d, p.val)
khenaidoob9203542018-09-17 22:56:37 -040092
khenaidoob9203542018-09-17 22:56:37 -040093 def reconcile_device(self, device):
94 return self.adapter.reconcile_device(device)
95
96 def abandon_device(self, device):
97 return self.adapter.abandon_device(device)
98
99 def disable_device(self, device):
khenaidoo92e62c52018-10-03 14:02:54 -0400100 d = Device()
101 if device:
102 device.Unpack(d)
103 return True, self.adapter.disable_device(d)
104 else:
105 return False, d
khenaidoob9203542018-09-17 22:56:37 -0400106
107 def reenable_device(self, device):
khenaidoo92e62c52018-10-03 14:02:54 -0400108 d = Device()
109 if device:
110 device.Unpack(d)
111 return True, self.adapter.reenable_device(d)
112 else:
113 return False, d
khenaidoob9203542018-09-17 22:56:37 -0400114
115 def reboot_device(self, device):
116 d = Device()
117 if device:
118 device.Unpack(d)
119 return (True, self.adapter.reboot_device(d))
120 else:
121 return (False, d)
122
123 def download_image(self, device, request):
124 return self.adapter.download_image(device, request)
125
126 def get_image_download_status(self, device, request):
127 return self.adapter.get_image_download_status(device, request)
128
129 def cancel_image_download(self, device, request):
130 return self.adapter.cancel_image_download(device, request)
131
132 def activate_image_update(self, device, request):
133 return self.adapter.activate_image_update(device, request)
134
135 def revert_image_update(self, device, request):
136 return self.adapter.revert_image_update(device, request)
137
138 def self_test(self, device):
139 return self.adapter.self_test_device(device)
140
141 def delete_device(self, device):
khenaidoo4d4802d2018-10-04 21:59:49 -0400142 d = Device()
143 if device:
144 device.Unpack(d)
145 return (True, self.adapter.delete_device(d))
146 else:
147 return (False, d)
khenaidoob9203542018-09-17 22:56:37 -0400148
149 def get_device_details(self, device):
150 return self.adapter.get_device_details(device)
151
152 def update_flows_bulk(self, device, flows, groups):
khenaidoo19d7b632018-10-30 10:49:50 -0400153 d = Device()
154 if device:
155 device.Unpack(d)
156 else:
157 return (False, d)
158
159 f = Flows()
160 if flows:
161 flows.Unpack(f)
162
163 g = FlowGroups()
164 if groups:
165 groups.Unpack(g)
166
167 return (True, self.adapter.update_flows_bulk(d, f, g))
khenaidoob9203542018-09-17 22:56:37 -0400168
169 def update_flows_incrementally(self, device, flow_changes, group_changes):
khenaidoo19d7b632018-10-30 10:49:50 -0400170 d = Device()
171 if device:
172 device.Unpack(d)
173 else:
174 return (False, d)
175
176 f = FlowChanges()
177 if flow_changes:
178 flow_changes.Unpack(f)
179
180 g = FlowGroupChanges()
181 if group_changes:
182 group_changes.Unpack(g)
183
184 return (True, self.adapter.update_flows_incrementally(d, f, g))
khenaidoob9203542018-09-17 22:56:37 -0400185
186 def suppress_alarm(self, filter):
187 return self.adapter.suppress_alarm(filter)
188
189 def unsuppress_alarm(self, filter):
190 return self.adapter.unsuppress_alarm(filter)
191
khenaidoo6fdf0ba2018-11-02 14:38:33 -0400192 def process_inter_adapter_message(self, msg):
193 m = InterAdapterMessage()
194 if msg:
195 msg.Unpack(m)
196 else:
197 return (False, m)
198
199 return (True, self.adapter.process_inter_adapter_message(m))