alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [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; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 20 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 21 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 22 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
| 23 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 24 | import org.projectfloodlight.openflow.protocol.OFType; |
| 25 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
| 26 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable; |
| 27 | import org.projectfloodlight.openflow.types.TableId; |
| 28 | |
| 29 | import java.util.Collections; |
| 30 | import java.util.List; |
| 31 | |
| 32 | /** |
| 33 | * Corsa switch driver for BGP Router deployment. |
| 34 | */ |
| 35 | public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch { |
| 36 | |
| 37 | private static final int VLAN_MPLS_TABLE = 1; |
| 38 | private static final int VLAN_TABLE = 2; |
| 39 | private static final int MPLS_TABLE = 3; |
| 40 | private static final int ETHER_TABLE = 4; |
| 41 | private static final int COS_MAP_TABLE = 5; |
| 42 | private static final int FIB_TABLE = 6; |
| 43 | private static final int LOCAL_TABLE = 9; |
| 44 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 45 | OFCorsaSwitchDriver(Dpid dpid, OFDescStatsReply desc) { |
| 46 | super(dpid); |
| 47 | |
| 48 | setSwitchDescription(desc); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void write(OFMessage msg) { |
| 53 | this.write(Collections.singletonList(msg)); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void write(List<OFMessage> msgs) { |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 58 | channel.write(msgs); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void sendMsg(OFMessage msg, TableType type) { |
| 63 | if (msg.getType() == OFType.FLOW_MOD) { |
| 64 | OFFlowMod flowMod = (OFFlowMod) msg; |
| 65 | OFFlowMod.Builder builder = flowMod.createBuilder(); |
| 66 | List<OFInstruction> instructions = builder.getInstructions(); |
| 67 | List<OFInstruction> newInstructions = Lists.newArrayList(); |
| 68 | for (OFInstruction i : instructions) { |
| 69 | if (i instanceof OFInstructionGotoTable) { |
| 70 | OFInstructionGotoTable gotoTable = (OFInstructionGotoTable) i; |
| 71 | TableType tid = TableType.values()[gotoTable.getTableId().getValue()]; |
| 72 | switch (tid) { |
| 73 | case VLAN_MPLS: |
| 74 | newInstructions.add( |
| 75 | gotoTable.createBuilder() |
| 76 | .setTableId(TableId.of(VLAN_MPLS_TABLE)).build()); |
| 77 | break; |
| 78 | case VLAN: |
| 79 | newInstructions.add( |
| 80 | gotoTable.createBuilder() |
| 81 | .setTableId(TableId.of(VLAN_TABLE)).build()); |
| 82 | break; |
| 83 | case ETHER: |
| 84 | newInstructions.add( |
| 85 | gotoTable.createBuilder() |
| 86 | .setTableId(TableId.of(ETHER_TABLE)).build()); |
| 87 | break; |
| 88 | case COS: |
| 89 | newInstructions.add( |
| 90 | gotoTable.createBuilder() |
| 91 | .setTableId(TableId.of(COS_MAP_TABLE)).build()); |
| 92 | break; |
| 93 | case IP: |
| 94 | newInstructions.add( |
| 95 | gotoTable.createBuilder() |
| 96 | .setTableId(TableId.of(FIB_TABLE)).build()); |
| 97 | break; |
| 98 | case MPLS: |
| 99 | newInstructions.add( |
| 100 | gotoTable.createBuilder() |
| 101 | .setTableId(TableId.of(MPLS_TABLE)).build()); |
| 102 | break; |
| 103 | case ACL: |
| 104 | newInstructions.add( |
| 105 | gotoTable.createBuilder() |
| 106 | .setTableId(TableId.of(LOCAL_TABLE)).build()); |
| 107 | break; |
| 108 | case NONE: |
| 109 | newInstructions.add( |
| 110 | gotoTable.createBuilder() |
| 111 | .setTableId(TableId.of(0)).build()); |
| 112 | break; |
| 113 | default: |
| 114 | log.warn("Unknown table type: {}", tid); |
| 115 | } |
| 116 | |
| 117 | } else { |
| 118 | newInstructions.add(i); |
| 119 | } |
| 120 | } |
| 121 | switch (type) { |
| 122 | case VLAN_MPLS: |
| 123 | builder.setTableId(TableId.of(VLAN_MPLS_TABLE)); |
| 124 | break; |
| 125 | case VLAN: |
| 126 | builder.setTableId(TableId.of(VLAN_TABLE)); |
| 127 | break; |
| 128 | case ETHER: |
| 129 | builder.setTableId(TableId.of(ETHER_TABLE)); |
| 130 | break; |
| 131 | case COS: |
| 132 | builder.setTableId(TableId.of(COS_MAP_TABLE)); |
| 133 | break; |
| 134 | case IP: |
| 135 | builder.setTableId(TableId.of(FIB_TABLE)); |
| 136 | break; |
| 137 | case MPLS: |
| 138 | builder.setTableId(TableId.of(MPLS_TABLE)); |
| 139 | break; |
| 140 | case ACL: |
| 141 | builder.setTableId(TableId.of(LOCAL_TABLE)); |
| 142 | break; |
| 143 | case NONE: |
| 144 | builder.setTableId(TableId.of(0)); |
| 145 | break; |
| 146 | default: |
| 147 | log.warn("Unknown table type: {}", type); |
| 148 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame^] | 149 | builder.setInstructions(newInstructions); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 150 | this.write(builder.build()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame^] | 151 | log.info("Installed {}", builder.build()); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 152 | } else { |
| 153 | this.write(msg); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public Boolean supportNxRole() { |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void startDriverHandshake() {} |
| 164 | |
| 165 | @Override |
| 166 | public boolean isDriverHandshakeComplete() { |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void processDriverHandshakeMessage(OFMessage m) {} |
| 172 | } |