sangho | c0b3c34 | 2015-03-12 17:12:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | package org.onosproject.openflow.drivers; |
| 17 | |
| 18 | import com.google.common.collect.Lists; |
| 19 | import org.onosproject.openflow.controller.Dpid; |
| 20 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 21 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
| 22 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 23 | import org.projectfloodlight.openflow.protocol.OFType; |
| 24 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
| 25 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable; |
| 26 | import org.projectfloodlight.openflow.types.TableId; |
| 27 | |
| 28 | import java.util.Collections; |
| 29 | import java.util.List; |
| 30 | |
| 31 | public class OFOVSSwitchCorsaTTP extends OFCorsaSwitchDriver { |
| 32 | |
| 33 | OFOVSSwitchCorsaTTP(Dpid dpid, OFDescStatsReply desc) { |
| 34 | super(dpid, desc); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void transformAndSendMsg(OFMessage msg, TableType type) { |
| 39 | log.trace("Trying to send {} of TableType {}", msg, type); |
| 40 | if (msg.getType() == OFType.FLOW_MOD) { |
| 41 | OFFlowMod flowMod = (OFFlowMod) msg; |
| 42 | OFFlowMod.Builder builder = flowMod.createBuilder(); |
| 43 | List<OFInstruction> instructions = flowMod.getInstructions(); |
| 44 | List<OFInstruction> newInstructions = Lists.newArrayList(); |
| 45 | for (OFInstruction i : instructions) { |
| 46 | if (i instanceof OFInstructionGotoTable) { |
| 47 | OFInstructionGotoTable gotoTable = (OFInstructionGotoTable) i; |
| 48 | TableType tid = TableType.values()[gotoTable.getTableId().getValue()]; |
| 49 | switch (tid) { |
| 50 | case VLAN_MPLS: |
| 51 | newInstructions.add( |
| 52 | gotoTable.createBuilder() |
| 53 | .setTableId(TableId.of(VLAN_MPLS_TABLE)).build()); |
| 54 | break; |
| 55 | case VLAN: |
| 56 | newInstructions.add( |
| 57 | gotoTable.createBuilder() |
| 58 | .setTableId(TableId.of(VLAN_TABLE)).build()); |
| 59 | break; |
| 60 | case ETHER: |
| 61 | newInstructions.add( |
| 62 | gotoTable.createBuilder() |
| 63 | .setTableId(TableId.of(ETHER_TABLE)).build()); |
| 64 | break; |
| 65 | case COS: |
| 66 | newInstructions.add( |
| 67 | gotoTable.createBuilder() |
| 68 | .setTableId(TableId.of(COS_MAP_TABLE)).build()); |
| 69 | break; |
| 70 | case IP: |
| 71 | newInstructions.add( |
| 72 | gotoTable.createBuilder() |
| 73 | .setTableId(TableId.of(FIB_TABLE)).build()); |
| 74 | break; |
| 75 | case MPLS: |
| 76 | newInstructions.add( |
| 77 | gotoTable.createBuilder() |
| 78 | .setTableId(TableId.of(MPLS_TABLE)).build()); |
| 79 | break; |
| 80 | case ACL: |
| 81 | newInstructions.add( |
| 82 | gotoTable.createBuilder() |
| 83 | .setTableId(TableId.of(LOCAL_TABLE)).build()); |
| 84 | break; |
| 85 | case NONE: |
| 86 | log.error("Should never have to go to Table 0"); |
| 87 | /*newInstructions.add( |
| 88 | gotoTable.createBuilder() |
| 89 | .setTableId(TableId.of(0)).build()); |
| 90 | */ |
| 91 | break; |
| 92 | default: |
| 93 | log.warn("Unknown table type: {}", tid); |
| 94 | } |
| 95 | } else { |
| 96 | newInstructions.add(i); |
| 97 | } |
| 98 | } |
| 99 | switch (type) { |
| 100 | case VLAN_MPLS: |
| 101 | builder.setTableId(TableId.of(VLAN_MPLS_TABLE)); |
| 102 | break; |
| 103 | case VLAN: |
| 104 | builder.setTableId(TableId.of(VLAN_TABLE)); |
| 105 | break; |
| 106 | case ETHER: |
| 107 | builder.setTableId(TableId.of(ETHER_TABLE)); |
| 108 | break; |
| 109 | case COS: |
| 110 | builder.setTableId(TableId.of(COS_MAP_TABLE)); |
| 111 | break; |
| 112 | case IP: |
| 113 | builder.setTableId(TableId.of(FIB_TABLE)); |
| 114 | break; |
| 115 | case MPLS: |
| 116 | builder.setTableId(TableId.of(MPLS_TABLE)); |
| 117 | break; |
| 118 | case ACL: |
| 119 | builder.setTableId(TableId.of(LOCAL_TABLE)); |
| 120 | break; |
| 121 | case FIRST: |
| 122 | builder.setTableId(TableId.of(FIRST_TABLE)); |
| 123 | break; |
| 124 | case NONE: |
| 125 | builder.setTableId(TableId.of(LOCAL_TABLE)); |
| 126 | break; |
| 127 | default: |
| 128 | log.warn("Unknown table type: {}", type); |
| 129 | } |
| 130 | builder.setInstructions(newInstructions); |
| 131 | OFMessage msgnew = builder.build(); |
| 132 | channel.write(Collections.singletonList(msgnew)); |
| 133 | log.debug("Installed {}", msgnew); |
| 134 | |
| 135 | } else { |
| 136 | channel.write(Collections.singletonList(msg)); |
| 137 | } |
| 138 | } |
| 139 | } |