Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 1 | # |
Zsolt Haraszti | 3eb27a5 | 2017-01-03 21:56:48 -0800 | [diff] [blame] | 2 | # Copyright 2017 the original author or authors. |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 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 | """ |
| 18 | Convert loxi objects to openflow_13 messages and back. |
| 19 | """ |
| 20 | from copy import copy |
| 21 | |
| 22 | from google.protobuf.descriptor import FieldDescriptor |
| 23 | |
| 24 | import loxi.of13 as of13 |
| 25 | from protobuf_to_dict import protobuf_to_dict, TYPE_CALLABLE_MAP |
| 26 | from protos import openflow_13_pb2 as pb2 |
| 27 | |
| 28 | |
| 29 | type_callable_map = copy(TYPE_CALLABLE_MAP) |
| 30 | type_callable_map.update({ |
| 31 | FieldDescriptor.TYPE_STRING: str |
| 32 | }) |
| 33 | |
| 34 | def pb2dict(pb): |
| 35 | """ |
| 36 | Convert protobuf to a dict of values good for instantiating |
| 37 | loxi objects (or any other objects). We specialize the protobuf_to_dict |
| 38 | library call with our modified decoders. |
| 39 | :param pb: protobuf as loaded into Python |
| 40 | :return: dict of values |
| 41 | """ |
| 42 | return protobuf_to_dict(pb, type_callable_map) |
| 43 | |
| 44 | def to_loxi(grpc_object): |
| 45 | cls = grpc_object.__class__ |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 46 | converter = to_loxi_converters[cls.__name__] |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 47 | return converter(grpc_object) |
| 48 | |
| 49 | def to_grpc(loxi_object): |
| 50 | cls = loxi_object.__class__ |
| 51 | converter = to_grpc_converters[cls] |
| 52 | return converter(loxi_object) |
| 53 | |
| 54 | def ofp_port_to_loxi_port_desc(pb): |
| 55 | kw = pb2dict(pb) |
| 56 | return of13.common.port_desc(**kw) |
| 57 | |
Zsolt Haraszti | 217a12e | 2016-12-19 16:37:55 -0800 | [diff] [blame] | 58 | def ofp_port_status_to_loxi_port_status(pb): |
| 59 | return of13.message.port_status( |
| 60 | reason=pb.reason, |
| 61 | desc=ofp_port_to_loxi_port_desc(pb.desc) |
| 62 | ) |
| 63 | |
Nicolas Palpacuer | fd7b8b1 | 2018-06-15 13:58:06 -0400 | [diff] [blame] | 64 | def ofp_port_stats_to_loxi_port_stats(pb): |
| 65 | kw = pb2dict(pb) |
| 66 | return of13.port_stats_entry(**kw) |
| 67 | |
Koray Kokten | 8592a23 | 2018-08-27 07:41:14 +0000 | [diff] [blame] | 68 | def ofp_meter_stats_to_loxi_meter_stats(pb): |
| 69 | kw = pb2dict(pb) |
| 70 | return of13.meter_stats(**kw) |
| 71 | |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 72 | def make_loxi_field(oxm_field): |
| 73 | assert oxm_field['oxm_class'] == pb2.OFPXMC_OPENFLOW_BASIC |
| 74 | ofb_field = oxm_field['ofb_field'] |
| 75 | field_type = ofb_field.get('type', 0) |
| 76 | |
| 77 | if field_type == pb2.OFPXMT_OFB_ETH_TYPE: |
| 78 | return ( |
| 79 | of13.oxm.eth_type(value=ofb_field['eth_type'])) |
| 80 | |
| 81 | elif field_type == pb2.OFPXMT_OFB_IN_PORT: |
| 82 | return ( |
| 83 | of13.oxm.in_port(value=ofb_field['port'])) |
| 84 | |
| 85 | elif field_type == pb2.OFPXMT_OFB_IP_PROTO: |
| 86 | return ( |
| 87 | of13.oxm.ip_proto(value=ofb_field['ip_proto'])) |
| 88 | |
| 89 | elif field_type == pb2.OFPXMT_OFB_VLAN_VID: |
| 90 | return ( |
| 91 | of13.oxm.vlan_vid(value=ofb_field['vlan_vid'])) |
| 92 | |
| 93 | elif field_type == pb2.OFPXMT_OFB_VLAN_PCP: |
| 94 | return ( |
| 95 | of13.oxm.vlan_pcp(value=ofb_field['vlan_pcp'])) |
| 96 | |
| 97 | elif field_type == pb2.OFPXMT_OFB_IPV4_SRC: |
| 98 | return ( |
| 99 | of13.oxm.ipv4_src(value=ofb_field['ipv4_src'])) |
| 100 | |
| 101 | elif field_type == pb2.OFPXMT_OFB_IPV4_DST: |
| 102 | return ( |
| 103 | of13.oxm.ipv4_dst(value=ofb_field['ipv4_dst'])) |
| 104 | |
| 105 | elif field_type == pb2.OFPXMT_OFB_UDP_SRC: |
| 106 | return ( |
| 107 | of13.oxm.udp_src(value=ofb_field['udp_src'])) |
| 108 | |
| 109 | elif field_type == pb2.OFPXMT_OFB_UDP_DST: |
| 110 | return ( |
| 111 | of13.oxm.udp_dst(value=ofb_field['udp_dst'])) |
| 112 | |
| 113 | elif field_type == pb2.OFPXMT_OFB_METADATA: |
| 114 | return ( |
| 115 | of13.oxm.metadata(value=ofb_field['table_metadata'])) |
| 116 | |
| 117 | else: |
| 118 | raise NotImplementedError( |
| 119 | 'OXM match field for type %s' % field_type) |
| 120 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 121 | def make_loxi_match(match): |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 122 | assert match.get('type', pb2.OFPMT_STANDARD) == pb2.OFPMT_OXM |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 123 | loxi_match_fields = [] |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 124 | for oxm_field in match.get('oxm_fields', []): |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 125 | loxi_match_fields.append(make_loxi_field(oxm_field)) |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 126 | return of13.match_v3(oxm_list=loxi_match_fields) |
| 127 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 128 | |
| 129 | def make_loxi_action(a): |
| 130 | if type(a) is not dict: |
| 131 | a = pb2dict(a) |
| 132 | |
| 133 | typ = a.get('type', 0) |
| 134 | |
| 135 | if typ == pb2.OFPAT_OUTPUT: |
| 136 | output_kws = a['output'] |
| 137 | return of13.action.output(**output_kws) |
| 138 | |
| 139 | elif typ == pb2.OFPAT_POP_VLAN: |
| 140 | return of13.action.pop_vlan() |
| 141 | |
| 142 | elif typ == pb2.OFPAT_PUSH_VLAN: |
| 143 | push_vlan_kws = a['push'] |
| 144 | return of13.action.push_vlan(**push_vlan_kws) |
| 145 | |
| 146 | elif typ == pb2.OFPAT_SET_FIELD: |
| 147 | loxi_field = make_loxi_field(a['set_field']['field']) |
| 148 | return of13.action.set_field(loxi_field) |
| 149 | |
| 150 | elif typ == pb2.OFPAT_GROUP: |
| 151 | group_kws = a['group'] |
| 152 | return of13.action.group(**group_kws) |
| 153 | |
| 154 | else: |
| 155 | raise NotImplementedError( |
| 156 | 'Action decoder for action OFPAT_* %d' % typ) |
| 157 | |
| 158 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 159 | def ofp_flow_stats_to_loxi_flow_stats(pb): |
| 160 | kw = pb2dict(pb) |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 161 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 162 | def make_loxi_instruction(inst): |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 163 | type = inst['type'] |
| 164 | if type == pb2.OFPIT_APPLY_ACTIONS: |
| 165 | return of13.instruction.apply_actions( |
| 166 | actions=[make_loxi_action(a) |
| 167 | for a in inst['actions']['actions']]) |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 168 | elif type == pb2.OFPIT_CLEAR_ACTIONS: |
| 169 | return of13.instruction.clear_actions() |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 170 | elif type == pb2.OFPIT_GOTO_TABLE: |
| 171 | return of13.instruction.goto_table( |
| 172 | table_id=inst['goto_table']['table_id']) |
| 173 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 174 | else: |
| 175 | raise NotImplementedError('Instruction type %d' % type) |
| 176 | |
| 177 | kw['match'] = make_loxi_match(kw['match']) |
| 178 | kw['instructions'] = [make_loxi_instruction(i) for i in kw['instructions']] |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 179 | del kw['id'] |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 180 | return of13.flow_stats_entry(**kw) |
| 181 | |
Zsolt Haraszti | 8925d1f | 2016-12-21 00:45:19 -0800 | [diff] [blame] | 182 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 183 | def ofp_packet_in_to_loxi_packet_in(pb): |
Zsolt Haraszti | 8925d1f | 2016-12-21 00:45:19 -0800 | [diff] [blame] | 184 | packet_in = of13.message.packet_in( |
| 185 | buffer_id=pb.buffer_id, |
| 186 | reason=pb.reason, |
| 187 | table_id=pb.table_id, |
| 188 | cookie=pb.cookie, |
| 189 | match=make_loxi_match(pb2dict(pb.match)), |
| 190 | data=pb.data |
| 191 | ) |
| 192 | return packet_in |
| 193 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 194 | def ofp_group_desc_to_loxi_group_desc(pb): |
| 195 | return of13.group_desc_stats_entry( |
| 196 | group_type=pb.type, |
| 197 | group_id=pb.group_id, |
| 198 | buckets=[to_loxi(bucket) for bucket in pb.buckets]) |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 199 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 200 | |
| 201 | def ofp_group_stats_to_loxi_group_stats(pb): |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 202 | return of13.group_stats_entry( |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 203 | group_id=pb.group_id, |
| 204 | ref_count=pb.ref_count, |
| 205 | packet_count=pb.packet_count, |
| 206 | byte_count=pb.byte_count, |
| 207 | duration_sec=pb.duration_sec, |
| 208 | duration_nsec=pb.duration_nsec, |
| 209 | bucket_stats=[to_loxi(bstat) for bstat in pb.bucket_stats]) |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 210 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 211 | |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 212 | def ofp_bucket_counter_to_loxy_bucket_counter(pb): |
| 213 | return of13.bucket_counter( |
| 214 | packet_count=pb.packet_count, |
| 215 | byte_count=pb.byte_count) |
| 216 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 217 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 218 | def ofp_bucket_to_loxi_bucket(pb): |
| 219 | return of13.bucket( |
| 220 | weight=pb.weight, |
| 221 | watch_port=pb.watch_port, |
| 222 | watch_group=pb.watch_group, |
| 223 | actions=[to_loxi(action) for action in pb.actions] |
| 224 | ) |
| 225 | |
| 226 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 227 | to_loxi_converters = { |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 228 | 'ofp_port': ofp_port_to_loxi_port_desc, |
| 229 | 'ofp_port_status': ofp_port_status_to_loxi_port_status, |
| 230 | 'ofp_flow_stats': ofp_flow_stats_to_loxi_flow_stats, |
| 231 | 'ofp_packet_in': ofp_packet_in_to_loxi_packet_in, |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 232 | 'ofp_group_stats': ofp_group_stats_to_loxi_group_stats, |
| 233 | 'ofp_group_desc': ofp_group_desc_to_loxi_group_desc, |
| 234 | 'ofp_bucket_counter': ofp_bucket_counter_to_loxy_bucket_counter, |
| 235 | 'ofp_bucket': ofp_bucket_to_loxi_bucket, |
Nicolas Palpacuer | fd7b8b1 | 2018-06-15 13:58:06 -0400 | [diff] [blame] | 236 | 'ofp_action': make_loxi_action, |
Koray Kokten | 8592a23 | 2018-08-27 07:41:14 +0000 | [diff] [blame] | 237 | 'ofp_port_stats': ofp_port_stats_to_loxi_port_stats, |
| 238 | 'ofp_meter_stats': ofp_meter_stats_to_loxi_meter_stats |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 241 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 242 | def loxi_flow_mod_to_ofp_flow_mod(lo): |
| 243 | return pb2.ofp_flow_mod( |
| 244 | cookie=lo.cookie, |
| 245 | cookie_mask=lo.cookie_mask, |
| 246 | table_id=lo.table_id, |
| 247 | command=lo._command, |
| 248 | idle_timeout=lo.idle_timeout, |
| 249 | hard_timeout=lo.hard_timeout, |
| 250 | priority=lo.priority, |
| 251 | buffer_id=lo.buffer_id, |
| 252 | out_port=lo.out_port, |
| 253 | out_group=lo.out_group, |
| 254 | flags=lo.flags, |
| 255 | match=to_grpc(lo.match), |
| 256 | instructions=[to_grpc(i) for i in lo.instructions]) |
| 257 | |
Koray Kokten | 8592a23 | 2018-08-27 07:41:14 +0000 | [diff] [blame] | 258 | def loxi_meter_mod_to_ofp_meter_mod(lo): |
| 259 | return pb2.ofp_meter_mod( |
| 260 | command=lo.command, |
| 261 | flags=lo.flags, |
| 262 | meter_id=lo.meter_id, |
| 263 | bands=[to_grpc(i) for i in lo.meters]) |
| 264 | |
| 265 | |
| 266 | def loxi_meter_band_drop_to_ofp_meter_band_drop(lo): |
| 267 | return pb2.ofp_meter_band_header( |
| 268 | type=lo.type, |
| 269 | rate=lo.rate, |
| 270 | burst_size=lo.burst_size) |
| 271 | |
| 272 | |
| 273 | def loxi_meter_band_dscp_remark_to_ofp_meter_band_dscp_remark(lo): |
| 274 | return pb2.ofp_meter_band_header( |
| 275 | type=lo.type, |
| 276 | rate=lo.rate, |
| 277 | burst_size=lo.burst_size, |
| 278 | dscp_remark=pb2.ofp_meter_band_dscp_remark(prec_level=lo.prec_level)) |
| 279 | |
| 280 | |
| 281 | def loxi_meter_band_experimenter_to_ofp_meter_band_experimenter(lo): |
| 282 | return pb2.ofp_meter_band_header( |
| 283 | type=lo.type, |
| 284 | rate=lo.rate, |
| 285 | burst_size=lo.burst_size, |
| 286 | experimenter=pb2.ofp_meter_band_experimenter(experimenter=lo.experimenter)) |
| 287 | |
| 288 | |
| 289 | def loxi_meter_multipart_request_to_ofp_meter_multipart_request(lo): |
| 290 | return pb2.ofp_meter_multipart_request( |
| 291 | meter_id=lo.meter_id) |
| 292 | |
| 293 | |
| 294 | def loxi_meter_stats_to_ofp_meter_stats(lo): |
| 295 | return pb2.ofp_meter_stats( |
| 296 | meter_id=lo.meter_id, |
| 297 | flow_count=lo.flow_count, |
| 298 | packet_in_count =lo.packet_in_count, |
| 299 | byte_in_count=lo.byte_in_count, |
| 300 | duration_sec=lo.duration_sec, |
| 301 | duration_nsec=lo.duration_nsec, |
| 302 | band_stats=lo.band_stats) |
| 303 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 304 | |
| 305 | def loxi_group_mod_to_ofp_group_mod(lo): |
| 306 | return pb2.ofp_group_mod( |
| 307 | command=lo.command, |
Zsolt Haraszti | 9125b1a | 2016-10-24 22:54:33 -0700 | [diff] [blame] | 308 | type=lo.group_type, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 309 | group_id=lo.group_id, |
| 310 | buckets=[to_grpc(b) for b in lo.buckets]) |
| 311 | |
| 312 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 313 | def loxi_packet_out_to_ofp_packet_out(lo): |
| 314 | return pb2.ofp_packet_out( |
| 315 | buffer_id=lo.buffer_id, |
| 316 | in_port=lo.in_port, |
| 317 | actions=[to_grpc(a) for a in lo.actions], |
| 318 | data=lo.data) |
| 319 | |
| 320 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 321 | def loxi_match_v3_to_ofp_match(lo): |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 322 | return pb2.ofp_match( |
| 323 | type=pb2.OFPMT_OXM, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 324 | oxm_fields=[to_grpc(f) for f in lo.oxm_list]) |
| 325 | |
| 326 | |
| 327 | def loxi_bucket_to_ofp_bucket(lo): |
| 328 | return pb2.ofp_bucket( |
| 329 | weight=lo.weight, |
| 330 | watch_port=lo.watch_port, |
| 331 | watch_group=lo.watch_group, |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 332 | actions=[to_grpc(a) for a in lo.actions]) |
| 333 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 334 | |
| 335 | def loxi_oxm_eth_type_to_ofp_oxm(lo): |
| 336 | return pb2.ofp_oxm_field( |
| 337 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 338 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 339 | type=pb2.OFPXMT_OFB_ETH_TYPE, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 340 | eth_type=lo.value)) |
| 341 | |
| 342 | |
| 343 | def loxi_oxm_in_port_to_ofp_oxm(lo): |
| 344 | return pb2.ofp_oxm_field( |
| 345 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 346 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 347 | type=pb2.OFPXMT_OFB_IN_PORT, |
| 348 | port=lo.value)) |
| 349 | |
| 350 | |
| 351 | def loxi_oxm_ip_proto_to_ofp_oxm(lo): |
| 352 | return pb2.ofp_oxm_field( |
| 353 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 354 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 355 | type=pb2.OFPXMT_OFB_IP_PROTO, |
| 356 | ip_proto=lo.value)) |
| 357 | |
| 358 | |
| 359 | def loxi_oxm_vlan_vid_to_ofp_oxm(lo): |
| 360 | return pb2.ofp_oxm_field( |
| 361 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 362 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 363 | type=pb2.OFPXMT_OFB_VLAN_VID, |
| 364 | vlan_vid=lo.value)) |
| 365 | |
| 366 | |
| 367 | def loxi_oxm_vlan_pcp_to_ofp_oxm(lo): |
| 368 | return pb2.ofp_oxm_field( |
| 369 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 370 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 371 | type=pb2.OFPXMT_OFB_VLAN_PCP, |
| 372 | vlan_pcp=lo.value)) |
| 373 | |
| 374 | |
| 375 | def loxi_oxm_ipv4_dst_to_ofp_oxm(lo): |
| 376 | return pb2.ofp_oxm_field( |
| 377 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 378 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 379 | type=pb2.OFPXMT_OFB_IPV4_DST, |
| 380 | ipv4_dst=lo.value)) |
| 381 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 382 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 383 | def loxi_oxm_udp_dst_to_ofp_oxm(lo): |
| 384 | return pb2.ofp_oxm_field( |
| 385 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 386 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 387 | type=pb2.OFPXMT_OFB_UDP_DST, |
| 388 | udp_dst=lo.value)) |
| 389 | |
| 390 | |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 391 | def loxi_oxm_udp_src_to_ofp_oxm(lo): |
| 392 | return pb2.ofp_oxm_field( |
| 393 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 394 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 395 | type=pb2.OFPXMT_OFB_UDP_SRC, |
| 396 | udp_src=lo.value)) |
| 397 | |
| 398 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 399 | def loxi_oxm_metadata_to_ofp_oxm(lo): |
| 400 | return pb2.ofp_oxm_field( |
| 401 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 402 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 403 | type=pb2.OFPXMT_OFB_METADATA, |
| 404 | table_metadata=lo.value)) |
| 405 | |
| 406 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 407 | def loxi_apply_actions_to_ofp_instruction(lo): |
| 408 | return pb2.ofp_instruction( |
| 409 | type=pb2.OFPIT_APPLY_ACTIONS, |
| 410 | actions=pb2.ofp_instruction_actions( |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 411 | actions=[to_grpc(a) for a in lo.actions])) |
| 412 | |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 413 | def loxi_clear_actions_to_ofp_instruction(lo): |
| 414 | return pb2.ofp_instruction( |
| 415 | type=pb2.OFPIT_CLEAR_ACTIONS) |
| 416 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 417 | |
| 418 | def loxi_goto_table_to_ofp_instruction(lo): |
| 419 | return pb2.ofp_instruction( |
| 420 | type=pb2.OFPIT_GOTO_TABLE, |
| 421 | goto_table=pb2.ofp_instruction_goto_table(table_id=lo.table_id)) |
| 422 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 423 | |
| 424 | def loxi_output_action_to_ofp_action(lo): |
| 425 | return pb2.ofp_action( |
| 426 | type=pb2.OFPAT_OUTPUT, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 427 | output=pb2.ofp_action_output(port=lo.port, max_len=lo.max_len)) |
| 428 | |
| 429 | |
| 430 | def loxi_group_action_to_ofp_action(lo): |
| 431 | return pb2.ofp_action( |
| 432 | type=pb2.OFPAT_GROUP, |
| 433 | group=pb2.ofp_action_group(group_id=lo.group_id)) |
| 434 | |
| 435 | |
| 436 | def loxi_set_field_action_to_ofp_action(lo): |
| 437 | return pb2.ofp_action( |
| 438 | type=pb2.OFPAT_SET_FIELD, |
| 439 | set_field=pb2.ofp_action_set_field(field=to_grpc(lo.field))) |
| 440 | |
| 441 | |
| 442 | def loxi_pop_vlan_action_to_ofp_action(lo): |
| 443 | return pb2.ofp_action(type=pb2.OFPAT_POP_VLAN) |
| 444 | |
| 445 | |
| 446 | def loxi_push_vlan_action_to_ofp_action(lo): |
| 447 | return pb2.ofp_action( |
| 448 | type=pb2.OFPAT_PUSH_VLAN, |
| 449 | push=pb2.ofp_action_push(ethertype=lo.ethertype)) |
| 450 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 451 | |
| 452 | to_grpc_converters = { |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 453 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 454 | of13.message.flow_add: loxi_flow_mod_to_ofp_flow_mod, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 455 | of13.message.flow_delete: loxi_flow_mod_to_ofp_flow_mod, |
| 456 | of13.message.flow_delete_strict: loxi_flow_mod_to_ofp_flow_mod, |
| 457 | of13.message.flow_modify: loxi_flow_mod_to_ofp_flow_mod, |
| 458 | of13.message.flow_modify_strict: loxi_flow_mod_to_ofp_flow_mod, |
Koray Kokten | 8592a23 | 2018-08-27 07:41:14 +0000 | [diff] [blame] | 459 | of13.message.meter_mod: loxi_meter_mod_to_ofp_meter_mod, |
| 460 | of13.message.meter_stats_request: loxi_meter_stats_to_ofp_meter_stats, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 461 | |
| 462 | of13.message.group_add: loxi_group_mod_to_ofp_group_mod, |
| 463 | of13.message.group_delete: loxi_group_mod_to_ofp_group_mod, |
| 464 | of13.message.group_modify: loxi_group_mod_to_ofp_group_mod, |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 465 | of13.message.packet_out: loxi_packet_out_to_ofp_packet_out, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 466 | |
Koray Kokten | 8592a23 | 2018-08-27 07:41:14 +0000 | [diff] [blame] | 467 | of13.meter_band.drop: loxi_meter_band_drop_to_ofp_meter_band_drop, |
| 468 | of13.meter_band.dscp_remark: loxi_meter_band_dscp_remark_to_ofp_meter_band_dscp_remark, |
| 469 | of13.meter_band.experimenter: loxi_meter_band_experimenter_to_ofp_meter_band_experimenter, |
| 470 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 471 | of13.common.match_v3: loxi_match_v3_to_ofp_match, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 472 | of13.common.bucket: loxi_bucket_to_ofp_bucket, |
| 473 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 474 | of13.oxm.eth_type: loxi_oxm_eth_type_to_ofp_oxm, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 475 | of13.oxm.in_port: loxi_oxm_in_port_to_ofp_oxm, |
| 476 | of13.oxm.ip_proto: loxi_oxm_ip_proto_to_ofp_oxm, |
| 477 | of13.oxm.vlan_vid: loxi_oxm_vlan_vid_to_ofp_oxm, |
| 478 | of13.oxm.vlan_pcp: loxi_oxm_vlan_pcp_to_ofp_oxm, |
| 479 | of13.oxm.ipv4_dst: loxi_oxm_ipv4_dst_to_ofp_oxm, |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 480 | of13.oxm.udp_src: loxi_oxm_udp_src_to_ofp_oxm, |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 481 | of13.oxm.udp_dst: loxi_oxm_udp_dst_to_ofp_oxm, |
| 482 | of13.oxm.metadata: loxi_oxm_metadata_to_ofp_oxm, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 483 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 484 | of13.instruction.apply_actions: loxi_apply_actions_to_ofp_instruction, |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 485 | of13.instruction.clear_actions: loxi_clear_actions_to_ofp_instruction, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 486 | of13.instruction.goto_table: loxi_goto_table_to_ofp_instruction, |
| 487 | |
| 488 | of13.action.output: loxi_output_action_to_ofp_action, |
| 489 | of13.action.group: loxi_group_action_to_ofp_action, |
| 490 | of13.action.set_field: loxi_set_field_action_to_ofp_action, |
| 491 | of13.action.pop_vlan: loxi_pop_vlan_action_to_ofp_action, |
| 492 | of13.action.push_vlan: loxi_push_vlan_action_to_ofp_action, |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 493 | } |