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']]) |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 160 | elif type == pb2.OFPIT_GOTO_TABLE: |
| 161 | return of13.instruction.goto_table( |
| 162 | table_id=inst['goto_table']['table_id']) |
| 163 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 164 | else: |
| 165 | raise NotImplementedError('Instruction type %d' % type) |
| 166 | |
| 167 | kw['match'] = make_loxi_match(kw['match']) |
| 168 | kw['instructions'] = [make_loxi_instruction(i) for i in kw['instructions']] |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 169 | del kw['id'] |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 170 | return of13.flow_stats_entry(**kw) |
| 171 | |
Zsolt Haraszti | 8925d1f | 2016-12-21 00:45:19 -0800 | [diff] [blame] | 172 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 173 | def ofp_packet_in_to_loxi_packet_in(pb): |
Zsolt Haraszti | 8925d1f | 2016-12-21 00:45:19 -0800 | [diff] [blame] | 174 | packet_in = of13.message.packet_in( |
| 175 | buffer_id=pb.buffer_id, |
| 176 | reason=pb.reason, |
| 177 | table_id=pb.table_id, |
| 178 | cookie=pb.cookie, |
| 179 | match=make_loxi_match(pb2dict(pb.match)), |
| 180 | data=pb.data |
| 181 | ) |
| 182 | return packet_in |
| 183 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 184 | def ofp_group_desc_to_loxi_group_desc(pb): |
| 185 | return of13.group_desc_stats_entry( |
| 186 | group_type=pb.type, |
| 187 | group_id=pb.group_id, |
| 188 | buckets=[to_loxi(bucket) for bucket in pb.buckets]) |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 189 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 190 | |
| 191 | def ofp_group_stats_to_loxi_group_stats(pb): |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 192 | return of13.group_stats_entry( |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 193 | group_id=pb.group_id, |
| 194 | ref_count=pb.ref_count, |
| 195 | packet_count=pb.packet_count, |
| 196 | byte_count=pb.byte_count, |
| 197 | duration_sec=pb.duration_sec, |
| 198 | duration_nsec=pb.duration_nsec, |
| 199 | bucket_stats=[to_loxi(bstat) for bstat in pb.bucket_stats]) |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 200 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 201 | |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 202 | def ofp_bucket_counter_to_loxy_bucket_counter(pb): |
| 203 | return of13.bucket_counter( |
| 204 | packet_count=pb.packet_count, |
| 205 | byte_count=pb.byte_count) |
| 206 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 207 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 208 | def ofp_bucket_to_loxi_bucket(pb): |
| 209 | return of13.bucket( |
| 210 | weight=pb.weight, |
| 211 | watch_port=pb.watch_port, |
| 212 | watch_group=pb.watch_group, |
| 213 | actions=[to_loxi(action) for action in pb.actions] |
| 214 | ) |
| 215 | |
| 216 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 217 | to_loxi_converters = { |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 218 | 'ofp_port': ofp_port_to_loxi_port_desc, |
| 219 | 'ofp_port_status': ofp_port_status_to_loxi_port_status, |
| 220 | 'ofp_flow_stats': ofp_flow_stats_to_loxi_flow_stats, |
| 221 | 'ofp_packet_in': ofp_packet_in_to_loxi_packet_in, |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 222 | 'ofp_group_stats': ofp_group_stats_to_loxi_group_stats, |
| 223 | 'ofp_group_desc': ofp_group_desc_to_loxi_group_desc, |
| 224 | 'ofp_bucket_counter': ofp_bucket_counter_to_loxy_bucket_counter, |
| 225 | 'ofp_bucket': ofp_bucket_to_loxi_bucket, |
| 226 | 'ofp_action': make_loxi_action |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 229 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 230 | def loxi_flow_mod_to_ofp_flow_mod(lo): |
| 231 | return pb2.ofp_flow_mod( |
| 232 | cookie=lo.cookie, |
| 233 | cookie_mask=lo.cookie_mask, |
| 234 | table_id=lo.table_id, |
| 235 | command=lo._command, |
| 236 | idle_timeout=lo.idle_timeout, |
| 237 | hard_timeout=lo.hard_timeout, |
| 238 | priority=lo.priority, |
| 239 | buffer_id=lo.buffer_id, |
| 240 | out_port=lo.out_port, |
| 241 | out_group=lo.out_group, |
| 242 | flags=lo.flags, |
| 243 | match=to_grpc(lo.match), |
| 244 | instructions=[to_grpc(i) for i in lo.instructions]) |
| 245 | |
| 246 | |
| 247 | def loxi_group_mod_to_ofp_group_mod(lo): |
| 248 | return pb2.ofp_group_mod( |
| 249 | command=lo.command, |
Zsolt Haraszti | 9125b1a | 2016-10-24 22:54:33 -0700 | [diff] [blame] | 250 | type=lo.group_type, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 251 | group_id=lo.group_id, |
| 252 | buckets=[to_grpc(b) for b in lo.buckets]) |
| 253 | |
| 254 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 255 | def loxi_packet_out_to_ofp_packet_out(lo): |
| 256 | return pb2.ofp_packet_out( |
| 257 | buffer_id=lo.buffer_id, |
| 258 | in_port=lo.in_port, |
| 259 | actions=[to_grpc(a) for a in lo.actions], |
| 260 | data=lo.data) |
| 261 | |
| 262 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 263 | def loxi_match_v3_to_ofp_match(lo): |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 264 | return pb2.ofp_match( |
| 265 | type=pb2.OFPMT_OXM, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 266 | oxm_fields=[to_grpc(f) for f in lo.oxm_list]) |
| 267 | |
| 268 | |
| 269 | def loxi_bucket_to_ofp_bucket(lo): |
| 270 | return pb2.ofp_bucket( |
| 271 | weight=lo.weight, |
| 272 | watch_port=lo.watch_port, |
| 273 | watch_group=lo.watch_group, |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 274 | actions=[to_grpc(a) for a in lo.actions]) |
| 275 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 276 | |
| 277 | def loxi_oxm_eth_type_to_ofp_oxm(lo): |
| 278 | return pb2.ofp_oxm_field( |
| 279 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 280 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 281 | type=pb2.OFPXMT_OFB_ETH_TYPE, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 282 | eth_type=lo.value)) |
| 283 | |
| 284 | |
| 285 | def loxi_oxm_in_port_to_ofp_oxm(lo): |
| 286 | return pb2.ofp_oxm_field( |
| 287 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 288 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 289 | type=pb2.OFPXMT_OFB_IN_PORT, |
| 290 | port=lo.value)) |
| 291 | |
| 292 | |
| 293 | def loxi_oxm_ip_proto_to_ofp_oxm(lo): |
| 294 | return pb2.ofp_oxm_field( |
| 295 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 296 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 297 | type=pb2.OFPXMT_OFB_IP_PROTO, |
| 298 | ip_proto=lo.value)) |
| 299 | |
| 300 | |
| 301 | def loxi_oxm_vlan_vid_to_ofp_oxm(lo): |
| 302 | return pb2.ofp_oxm_field( |
| 303 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 304 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 305 | type=pb2.OFPXMT_OFB_VLAN_VID, |
| 306 | vlan_vid=lo.value)) |
| 307 | |
| 308 | |
| 309 | def loxi_oxm_vlan_pcp_to_ofp_oxm(lo): |
| 310 | return pb2.ofp_oxm_field( |
| 311 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 312 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 313 | type=pb2.OFPXMT_OFB_VLAN_PCP, |
| 314 | vlan_pcp=lo.value)) |
| 315 | |
| 316 | |
| 317 | def loxi_oxm_ipv4_dst_to_ofp_oxm(lo): |
| 318 | return pb2.ofp_oxm_field( |
| 319 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 320 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 321 | type=pb2.OFPXMT_OFB_IPV4_DST, |
| 322 | ipv4_dst=lo.value)) |
| 323 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 324 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 325 | def loxi_oxm_udp_dst_to_ofp_oxm(lo): |
| 326 | return pb2.ofp_oxm_field( |
| 327 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 328 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 329 | type=pb2.OFPXMT_OFB_UDP_DST, |
| 330 | udp_dst=lo.value)) |
| 331 | |
| 332 | |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 333 | def loxi_oxm_udp_src_to_ofp_oxm(lo): |
| 334 | return pb2.ofp_oxm_field( |
| 335 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 336 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 337 | type=pb2.OFPXMT_OFB_UDP_SRC, |
| 338 | udp_src=lo.value)) |
| 339 | |
| 340 | |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 341 | def loxi_oxm_metadata_to_ofp_oxm(lo): |
| 342 | return pb2.ofp_oxm_field( |
| 343 | oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, |
| 344 | ofb_field=pb2.ofp_oxm_ofb_field( |
| 345 | type=pb2.OFPXMT_OFB_METADATA, |
| 346 | table_metadata=lo.value)) |
| 347 | |
| 348 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 349 | def loxi_apply_actions_to_ofp_instruction(lo): |
| 350 | return pb2.ofp_instruction( |
| 351 | type=pb2.OFPIT_APPLY_ACTIONS, |
| 352 | actions=pb2.ofp_instruction_actions( |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 353 | actions=[to_grpc(a) for a in lo.actions])) |
| 354 | |
| 355 | |
| 356 | def loxi_goto_table_to_ofp_instruction(lo): |
| 357 | return pb2.ofp_instruction( |
| 358 | type=pb2.OFPIT_GOTO_TABLE, |
| 359 | goto_table=pb2.ofp_instruction_goto_table(table_id=lo.table_id)) |
| 360 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 361 | |
| 362 | def loxi_output_action_to_ofp_action(lo): |
| 363 | return pb2.ofp_action( |
| 364 | type=pb2.OFPAT_OUTPUT, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 365 | output=pb2.ofp_action_output(port=lo.port, max_len=lo.max_len)) |
| 366 | |
| 367 | |
| 368 | def loxi_group_action_to_ofp_action(lo): |
| 369 | return pb2.ofp_action( |
| 370 | type=pb2.OFPAT_GROUP, |
| 371 | group=pb2.ofp_action_group(group_id=lo.group_id)) |
| 372 | |
| 373 | |
| 374 | def loxi_set_field_action_to_ofp_action(lo): |
| 375 | return pb2.ofp_action( |
| 376 | type=pb2.OFPAT_SET_FIELD, |
| 377 | set_field=pb2.ofp_action_set_field(field=to_grpc(lo.field))) |
| 378 | |
| 379 | |
| 380 | def loxi_pop_vlan_action_to_ofp_action(lo): |
| 381 | return pb2.ofp_action(type=pb2.OFPAT_POP_VLAN) |
| 382 | |
| 383 | |
| 384 | def loxi_push_vlan_action_to_ofp_action(lo): |
| 385 | return pb2.ofp_action( |
| 386 | type=pb2.OFPAT_PUSH_VLAN, |
| 387 | push=pb2.ofp_action_push(ethertype=lo.ethertype)) |
| 388 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 389 | |
| 390 | to_grpc_converters = { |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 391 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 392 | of13.message.flow_add: loxi_flow_mod_to_ofp_flow_mod, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 393 | of13.message.flow_delete: loxi_flow_mod_to_ofp_flow_mod, |
| 394 | of13.message.flow_delete_strict: loxi_flow_mod_to_ofp_flow_mod, |
| 395 | of13.message.flow_modify: loxi_flow_mod_to_ofp_flow_mod, |
| 396 | of13.message.flow_modify_strict: loxi_flow_mod_to_ofp_flow_mod, |
| 397 | |
| 398 | of13.message.group_add: loxi_group_mod_to_ofp_group_mod, |
| 399 | of13.message.group_delete: loxi_group_mod_to_ofp_group_mod, |
| 400 | of13.message.group_modify: loxi_group_mod_to_ofp_group_mod, |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 401 | of13.message.packet_out: loxi_packet_out_to_ofp_packet_out, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 402 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 403 | of13.common.match_v3: loxi_match_v3_to_ofp_match, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 404 | of13.common.bucket: loxi_bucket_to_ofp_bucket, |
| 405 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 406 | of13.oxm.eth_type: loxi_oxm_eth_type_to_ofp_oxm, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 407 | of13.oxm.in_port: loxi_oxm_in_port_to_ofp_oxm, |
| 408 | of13.oxm.ip_proto: loxi_oxm_ip_proto_to_ofp_oxm, |
| 409 | of13.oxm.vlan_vid: loxi_oxm_vlan_vid_to_ofp_oxm, |
| 410 | of13.oxm.vlan_pcp: loxi_oxm_vlan_pcp_to_ofp_oxm, |
| 411 | of13.oxm.ipv4_dst: loxi_oxm_ipv4_dst_to_ofp_oxm, |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 412 | of13.oxm.udp_src: loxi_oxm_udp_src_to_ofp_oxm, |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 413 | of13.oxm.udp_dst: loxi_oxm_udp_dst_to_ofp_oxm, |
| 414 | of13.oxm.metadata: loxi_oxm_metadata_to_ofp_oxm, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 415 | |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 416 | of13.instruction.apply_actions: loxi_apply_actions_to_ofp_instruction, |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 417 | of13.instruction.goto_table: loxi_goto_table_to_ofp_instruction, |
| 418 | |
| 419 | of13.action.output: loxi_output_action_to_ofp_action, |
| 420 | of13.action.group: loxi_group_action_to_ofp_action, |
| 421 | of13.action.set_field: loxi_set_field_action_to_ofp_action, |
| 422 | of13.action.pop_vlan: loxi_pop_vlan_action_to_ofp_action, |
| 423 | of13.action.push_vlan: loxi_push_vlan_action_to_ofp_action, |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 424 | } |