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