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 | |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 64 | def make_loxi_field(oxm_field): |
| 65 | assert oxm_field['oxm_class'] == pb2.OFPXMC_OPENFLOW_BASIC |
| 66 | ofb_field = oxm_field['ofb_field'] |
| 67 | field_type = ofb_field.get('type', 0) |
| 68 | |
| 69 | if field_type == pb2.OFPXMT_OFB_ETH_TYPE: |
| 70 | return ( |
| 71 | of13.oxm.eth_type(value=ofb_field['eth_type'])) |
| 72 | |
| 73 | elif field_type == pb2.OFPXMT_OFB_IN_PORT: |
| 74 | return ( |
| 75 | of13.oxm.in_port(value=ofb_field['port'])) |
| 76 | |
| 77 | elif field_type == pb2.OFPXMT_OFB_IP_PROTO: |
| 78 | return ( |
| 79 | of13.oxm.ip_proto(value=ofb_field['ip_proto'])) |
| 80 | |
| 81 | elif field_type == pb2.OFPXMT_OFB_VLAN_VID: |
| 82 | return ( |
| 83 | of13.oxm.vlan_vid(value=ofb_field['vlan_vid'])) |
| 84 | |
| 85 | elif field_type == pb2.OFPXMT_OFB_VLAN_PCP: |
| 86 | return ( |
| 87 | of13.oxm.vlan_pcp(value=ofb_field['vlan_pcp'])) |
| 88 | |
| 89 | elif field_type == pb2.OFPXMT_OFB_IPV4_SRC: |
| 90 | return ( |
| 91 | of13.oxm.ipv4_src(value=ofb_field['ipv4_src'])) |
| 92 | |
| 93 | elif field_type == pb2.OFPXMT_OFB_IPV4_DST: |
| 94 | return ( |
| 95 | of13.oxm.ipv4_dst(value=ofb_field['ipv4_dst'])) |
| 96 | |
| 97 | elif field_type == pb2.OFPXMT_OFB_UDP_SRC: |
| 98 | return ( |
| 99 | of13.oxm.udp_src(value=ofb_field['udp_src'])) |
| 100 | |
| 101 | elif field_type == pb2.OFPXMT_OFB_UDP_DST: |
| 102 | return ( |
| 103 | of13.oxm.udp_dst(value=ofb_field['udp_dst'])) |
| 104 | |
| 105 | elif field_type == pb2.OFPXMT_OFB_METADATA: |
| 106 | return ( |
| 107 | of13.oxm.metadata(value=ofb_field['table_metadata'])) |
| 108 | |
| 109 | else: |
| 110 | raise NotImplementedError( |
| 111 | 'OXM match field for type %s' % field_type) |
| 112 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 113 | def make_loxi_match(match): |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 114 | assert match.get('type', pb2.OFPMT_STANDARD) == pb2.OFPMT_OXM |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 115 | loxi_match_fields = [] |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 116 | for oxm_field in match.get('oxm_fields', []): |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 117 | loxi_match_fields.append(make_loxi_field(oxm_field)) |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 118 | return of13.match_v3(oxm_list=loxi_match_fields) |
| 119 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 120 | |
| 121 | def make_loxi_action(a): |
| 122 | if type(a) is not dict: |
| 123 | a = pb2dict(a) |
| 124 | |
| 125 | typ = a.get('type', 0) |
| 126 | |
| 127 | if typ == pb2.OFPAT_OUTPUT: |
| 128 | output_kws = a['output'] |
| 129 | return of13.action.output(**output_kws) |
| 130 | |
| 131 | elif typ == pb2.OFPAT_POP_VLAN: |
| 132 | return of13.action.pop_vlan() |
| 133 | |
| 134 | elif typ == pb2.OFPAT_PUSH_VLAN: |
| 135 | push_vlan_kws = a['push'] |
| 136 | return of13.action.push_vlan(**push_vlan_kws) |
| 137 | |
| 138 | elif typ == pb2.OFPAT_SET_FIELD: |
| 139 | loxi_field = make_loxi_field(a['set_field']['field']) |
| 140 | return of13.action.set_field(loxi_field) |
| 141 | |
| 142 | elif typ == pb2.OFPAT_GROUP: |
| 143 | group_kws = a['group'] |
| 144 | return of13.action.group(**group_kws) |
| 145 | |
| 146 | else: |
| 147 | raise NotImplementedError( |
| 148 | 'Action decoder for action OFPAT_* %d' % typ) |
| 149 | |
| 150 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 151 | def ofp_flow_stats_to_loxi_flow_stats(pb): |
| 152 | kw = pb2dict(pb) |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 153 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 154 | def make_loxi_instruction(inst): |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 155 | type = inst['type'] |
| 156 | if type == pb2.OFPIT_APPLY_ACTIONS: |
| 157 | return of13.instruction.apply_actions( |
| 158 | actions=[make_loxi_action(a) |
| 159 | for a in inst['actions']['actions']]) |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 160 | elif type == pb2.OFPIT_CLEAR_ACTIONS: |
| 161 | return of13.instruction.clear_actions() |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 162 | elif type == pb2.OFPIT_GOTO_TABLE: |
| 163 | return of13.instruction.goto_table( |
| 164 | table_id=inst['goto_table']['table_id']) |
| 165 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 166 | else: |
| 167 | raise NotImplementedError('Instruction type %d' % type) |
| 168 | |
| 169 | kw['match'] = make_loxi_match(kw['match']) |
| 170 | kw['instructions'] = [make_loxi_instruction(i) for i in kw['instructions']] |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 171 | del kw['id'] |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 172 | return of13.flow_stats_entry(**kw) |
| 173 | |
Zsolt Haraszti | 8925d1f | 2016-12-21 00:45:19 -0800 | [diff] [blame] | 174 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 175 | def ofp_packet_in_to_loxi_packet_in(pb): |
Zsolt Haraszti | 8925d1f | 2016-12-21 00:45:19 -0800 | [diff] [blame] | 176 | packet_in = of13.message.packet_in( |
| 177 | buffer_id=pb.buffer_id, |
| 178 | reason=pb.reason, |
| 179 | table_id=pb.table_id, |
| 180 | cookie=pb.cookie, |
| 181 | match=make_loxi_match(pb2dict(pb.match)), |
| 182 | data=pb.data |
| 183 | ) |
| 184 | return packet_in |
| 185 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 186 | def ofp_group_desc_to_loxi_group_desc(pb): |
| 187 | return of13.group_desc_stats_entry( |
| 188 | group_type=pb.type, |
| 189 | group_id=pb.group_id, |
| 190 | buckets=[to_loxi(bucket) for bucket in pb.buckets]) |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 191 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 192 | |
| 193 | def ofp_group_stats_to_loxi_group_stats(pb): |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 194 | return of13.group_stats_entry( |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 195 | group_id=pb.group_id, |
| 196 | ref_count=pb.ref_count, |
| 197 | packet_count=pb.packet_count, |
| 198 | byte_count=pb.byte_count, |
| 199 | duration_sec=pb.duration_sec, |
| 200 | duration_nsec=pb.duration_nsec, |
| 201 | bucket_stats=[to_loxi(bstat) for bstat in pb.bucket_stats]) |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 202 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 203 | |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 204 | def ofp_bucket_counter_to_loxy_bucket_counter(pb): |
| 205 | return of13.bucket_counter( |
| 206 | packet_count=pb.packet_count, |
| 207 | byte_count=pb.byte_count) |
| 208 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 209 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 210 | def ofp_bucket_to_loxi_bucket(pb): |
| 211 | return of13.bucket( |
| 212 | weight=pb.weight, |
| 213 | watch_port=pb.watch_port, |
| 214 | watch_group=pb.watch_group, |
| 215 | actions=[to_loxi(action) for action in pb.actions] |
| 216 | ) |
| 217 | |
| 218 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 219 | to_loxi_converters = { |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 220 | 'ofp_port': ofp_port_to_loxi_port_desc, |
| 221 | 'ofp_port_status': ofp_port_status_to_loxi_port_status, |
| 222 | 'ofp_flow_stats': ofp_flow_stats_to_loxi_flow_stats, |
| 223 | 'ofp_packet_in': ofp_packet_in_to_loxi_packet_in, |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 224 | 'ofp_group_stats': ofp_group_stats_to_loxi_group_stats, |
| 225 | 'ofp_group_desc': ofp_group_desc_to_loxi_group_desc, |
| 226 | 'ofp_bucket_counter': ofp_bucket_counter_to_loxy_bucket_counter, |
| 227 | 'ofp_bucket': ofp_bucket_to_loxi_bucket, |
| 228 | 'ofp_action': make_loxi_action |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 231 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 232 | def loxi_flow_mod_to_ofp_flow_mod(lo): |
| 233 | return pb2.ofp_flow_mod( |
| 234 | cookie=lo.cookie, |
| 235 | cookie_mask=lo.cookie_mask, |
| 236 | table_id=lo.table_id, |
| 237 | command=lo._command, |
| 238 | idle_timeout=lo.idle_timeout, |
| 239 | hard_timeout=lo.hard_timeout, |
| 240 | priority=lo.priority, |
| 241 | buffer_id=lo.buffer_id, |
| 242 | out_port=lo.out_port, |
| 243 | out_group=lo.out_group, |
| 244 | flags=lo.flags, |
| 245 | match=to_grpc(lo.match), |
| 246 | instructions=[to_grpc(i) for i in lo.instructions]) |
| 247 | |
| 248 | |
| 249 | def loxi_group_mod_to_ofp_group_mod(lo): |
| 250 | return pb2.ofp_group_mod( |
| 251 | command=lo.command, |
Zsolt Haraszti | 9125b1a | 2016-10-24 22:54:33 -0700 | [diff] [blame] | 252 | type=lo.group_type, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 253 | group_id=lo.group_id, |
| 254 | buckets=[to_grpc(b) for b in lo.buckets]) |
| 255 | |
| 256 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 257 | def loxi_packet_out_to_ofp_packet_out(lo): |
| 258 | return pb2.ofp_packet_out( |
| 259 | buffer_id=lo.buffer_id, |
| 260 | in_port=lo.in_port, |
| 261 | actions=[to_grpc(a) for a in lo.actions], |
| 262 | data=lo.data) |
| 263 | |
| 264 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 265 | def loxi_match_v3_to_ofp_match(lo): |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 266 | return pb2.ofp_match( |
| 267 | type=pb2.OFPMT_OXM, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 268 | oxm_fields=[to_grpc(f) for f in lo.oxm_list]) |
| 269 | |
| 270 | |
| 271 | def loxi_bucket_to_ofp_bucket(lo): |
| 272 | return pb2.ofp_bucket( |
| 273 | weight=lo.weight, |
| 274 | watch_port=lo.watch_port, |
| 275 | watch_group=lo.watch_group, |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 276 | actions=[to_grpc(a) for a in lo.actions]) |
| 277 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 278 | |
| 279 | def loxi_oxm_eth_type_to_ofp_oxm(lo): |
| 280 | return pb2.ofp_oxm_field( |
| 281 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 282 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 283 | type=pb2.OFPXMT_OFB_ETH_TYPE, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 284 | eth_type=lo.value)) |
| 285 | |
| 286 | |
| 287 | def loxi_oxm_in_port_to_ofp_oxm(lo): |
| 288 | return pb2.ofp_oxm_field( |
| 289 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 290 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 291 | type=pb2.OFPXMT_OFB_IN_PORT, |
| 292 | port=lo.value)) |
| 293 | |
| 294 | |
| 295 | def loxi_oxm_ip_proto_to_ofp_oxm(lo): |
| 296 | return pb2.ofp_oxm_field( |
| 297 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 298 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 299 | type=pb2.OFPXMT_OFB_IP_PROTO, |
| 300 | ip_proto=lo.value)) |
| 301 | |
| 302 | |
| 303 | def loxi_oxm_vlan_vid_to_ofp_oxm(lo): |
| 304 | return pb2.ofp_oxm_field( |
| 305 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 306 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 307 | type=pb2.OFPXMT_OFB_VLAN_VID, |
| 308 | vlan_vid=lo.value)) |
| 309 | |
| 310 | |
| 311 | def loxi_oxm_vlan_pcp_to_ofp_oxm(lo): |
| 312 | return pb2.ofp_oxm_field( |
| 313 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 314 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 315 | type=pb2.OFPXMT_OFB_VLAN_PCP, |
| 316 | vlan_pcp=lo.value)) |
| 317 | |
| 318 | |
| 319 | def loxi_oxm_ipv4_dst_to_ofp_oxm(lo): |
| 320 | return pb2.ofp_oxm_field( |
| 321 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 322 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 323 | type=pb2.OFPXMT_OFB_IPV4_DST, |
| 324 | ipv4_dst=lo.value)) |
| 325 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 326 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 327 | def loxi_oxm_udp_dst_to_ofp_oxm(lo): |
| 328 | return pb2.ofp_oxm_field( |
| 329 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 330 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 331 | type=pb2.OFPXMT_OFB_UDP_DST, |
| 332 | udp_dst=lo.value)) |
| 333 | |
| 334 | |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 335 | def loxi_oxm_udp_src_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_UDP_SRC, |
| 340 | udp_src=lo.value)) |
| 341 | |
| 342 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 343 | def loxi_oxm_metadata_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_METADATA, |
| 348 | table_metadata=lo.value)) |
| 349 | |
| 350 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 351 | def loxi_apply_actions_to_ofp_instruction(lo): |
| 352 | return pb2.ofp_instruction( |
| 353 | type=pb2.OFPIT_APPLY_ACTIONS, |
| 354 | actions=pb2.ofp_instruction_actions( |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 355 | actions=[to_grpc(a) for a in lo.actions])) |
| 356 | |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 357 | def loxi_clear_actions_to_ofp_instruction(lo): |
| 358 | return pb2.ofp_instruction( |
| 359 | type=pb2.OFPIT_CLEAR_ACTIONS) |
| 360 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 361 | |
| 362 | def loxi_goto_table_to_ofp_instruction(lo): |
| 363 | return pb2.ofp_instruction( |
| 364 | type=pb2.OFPIT_GOTO_TABLE, |
| 365 | goto_table=pb2.ofp_instruction_goto_table(table_id=lo.table_id)) |
| 366 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 367 | |
| 368 | def loxi_output_action_to_ofp_action(lo): |
| 369 | return pb2.ofp_action( |
| 370 | type=pb2.OFPAT_OUTPUT, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 371 | output=pb2.ofp_action_output(port=lo.port, max_len=lo.max_len)) |
| 372 | |
| 373 | |
| 374 | def loxi_group_action_to_ofp_action(lo): |
| 375 | return pb2.ofp_action( |
| 376 | type=pb2.OFPAT_GROUP, |
| 377 | group=pb2.ofp_action_group(group_id=lo.group_id)) |
| 378 | |
| 379 | |
| 380 | def loxi_set_field_action_to_ofp_action(lo): |
| 381 | return pb2.ofp_action( |
| 382 | type=pb2.OFPAT_SET_FIELD, |
| 383 | set_field=pb2.ofp_action_set_field(field=to_grpc(lo.field))) |
| 384 | |
| 385 | |
| 386 | def loxi_pop_vlan_action_to_ofp_action(lo): |
| 387 | return pb2.ofp_action(type=pb2.OFPAT_POP_VLAN) |
| 388 | |
| 389 | |
| 390 | def loxi_push_vlan_action_to_ofp_action(lo): |
| 391 | return pb2.ofp_action( |
| 392 | type=pb2.OFPAT_PUSH_VLAN, |
| 393 | push=pb2.ofp_action_push(ethertype=lo.ethertype)) |
| 394 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 395 | |
| 396 | to_grpc_converters = { |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 397 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 398 | of13.message.flow_add: loxi_flow_mod_to_ofp_flow_mod, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 399 | of13.message.flow_delete: loxi_flow_mod_to_ofp_flow_mod, |
| 400 | of13.message.flow_delete_strict: loxi_flow_mod_to_ofp_flow_mod, |
| 401 | of13.message.flow_modify: loxi_flow_mod_to_ofp_flow_mod, |
| 402 | of13.message.flow_modify_strict: loxi_flow_mod_to_ofp_flow_mod, |
| 403 | |
| 404 | of13.message.group_add: loxi_group_mod_to_ofp_group_mod, |
| 405 | of13.message.group_delete: loxi_group_mod_to_ofp_group_mod, |
| 406 | of13.message.group_modify: loxi_group_mod_to_ofp_group_mod, |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 407 | of13.message.packet_out: loxi_packet_out_to_ofp_packet_out, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 408 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 409 | of13.common.match_v3: loxi_match_v3_to_ofp_match, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 410 | of13.common.bucket: loxi_bucket_to_ofp_bucket, |
| 411 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 412 | of13.oxm.eth_type: loxi_oxm_eth_type_to_ofp_oxm, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 413 | of13.oxm.in_port: loxi_oxm_in_port_to_ofp_oxm, |
| 414 | of13.oxm.ip_proto: loxi_oxm_ip_proto_to_ofp_oxm, |
| 415 | of13.oxm.vlan_vid: loxi_oxm_vlan_vid_to_ofp_oxm, |
| 416 | of13.oxm.vlan_pcp: loxi_oxm_vlan_pcp_to_ofp_oxm, |
| 417 | of13.oxm.ipv4_dst: loxi_oxm_ipv4_dst_to_ofp_oxm, |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 418 | of13.oxm.udp_src: loxi_oxm_udp_src_to_ofp_oxm, |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 419 | of13.oxm.udp_dst: loxi_oxm_udp_dst_to_ofp_oxm, |
| 420 | of13.oxm.metadata: loxi_oxm_metadata_to_ofp_oxm, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 421 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 422 | of13.instruction.apply_actions: loxi_apply_actions_to_ofp_instruction, |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 423 | of13.instruction.clear_actions: loxi_clear_actions_to_ofp_instruction, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 424 | of13.instruction.goto_table: loxi_goto_table_to_ofp_instruction, |
| 425 | |
| 426 | of13.action.output: loxi_output_action_to_ofp_action, |
| 427 | of13.action.group: loxi_group_action_to_ofp_action, |
| 428 | of13.action.set_field: loxi_set_field_action_to_ofp_action, |
| 429 | of13.action.pop_vlan: loxi_pop_vlan_action_to_ofp_action, |
| 430 | of13.action.push_vlan: loxi_push_vlan_action_to_ofp_action, |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 431 | } |