Open Kilda Java Documentation
OutputCommands.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.floodlight.test.standard;
17 
18 import static java.util.Collections.singletonList;
21 import static org.openkilda.messaging.Utils.ETH_TYPE;
22 import static org.projectfloodlight.openflow.protocol.OFMeterFlags.BURST;
23 import static org.projectfloodlight.openflow.protocol.OFMeterFlags.KBPS;
24 import static org.projectfloodlight.openflow.protocol.OFMeterModCommand.ADD;
25 
26 import net.floodlightcontroller.util.FlowModUtils;
28 import org.projectfloodlight.openflow.protocol.OFFactory;
29 import org.projectfloodlight.openflow.protocol.OFFlowAdd;
30 import org.projectfloodlight.openflow.protocol.OFMeterMod;
31 import org.projectfloodlight.openflow.protocol.match.MatchField;
32 import org.projectfloodlight.openflow.types.EthType;
33 import org.projectfloodlight.openflow.types.OFBufferId;
34 import org.projectfloodlight.openflow.types.OFPort;
35 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
36 import org.projectfloodlight.openflow.types.U64;
37 
38 import java.util.Arrays;
39 import java.util.HashSet;
40 
41 public interface OutputCommands {
42  OFFactory ofFactory = new OFFactoryMock();
43 
44  OFFlowAdd egressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long cookie);
45 
46  OFFlowAdd egressPopFlowMod(int inputPort, int outputPort, int transitVlanId, long cookie);
47 
48  OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlanId, int outputVlan, long cookie);
49 
50  OFFlowAdd egressNoneFlowMod(int inputPort, int outputPort, int transitVlanId, long cookie);
51 
52  OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan,
53  long meterId, long cookie);
54 
55  OFFlowAdd ingressNoMatchVlanIdFlowMod(int inputPort, int outputPort, int transitVlan,
56  long meterId, long cookie);
57 
58  default OFFlowAdd ingressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan,
59  long meterId, long cookie) {
60  return ingressMatchVlanIdFlowMod(inputPort, outputPort, inputVlan, transitVlan, meterId, cookie);
61  }
62 
63  default OFFlowAdd ingressNoneFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie) {
64  return ingressNoMatchVlanIdFlowMod(inputPort, outputPort, transitVlan, meterId, cookie);
65  }
66 
67  default OFFlowAdd ingressPushFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie) {
68  return ingressNoMatchVlanIdFlowMod(inputPort, outputPort, transitVlan, meterId, cookie);
69  }
70 
71  default OFFlowAdd ingressPopFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan,
72  long meterId, long cookie) {
73  return ingressMatchVlanIdFlowMod(inputPort, outputPort, inputVlan, transitVlan, meterId, cookie);
74  }
75 
76  default OFFlowAdd transitFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) {
77  return ofFactory.buildFlowAdd()
78  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
79  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
80  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
81  .setBufferId(OFBufferId.NO_BUFFER)
82  .setPriority(DEFAULT_RULE_PRIORITY)
83  .setMatch(ofFactory.buildMatch()
84  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
85  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan))
86  .build())
87  .setInstructions(singletonList(
88  ofFactory.instructions().applyActions(singletonList(
89  ofFactory.actions().buildOutput()
90  .setMaxLen(0xFFFFFFFF)
91  .setPort(OFPort.of(outputPort))
92  .build()))
93  .createBuilder()
94  .build()))
95  .setXid(0L)
96  .build();
97  }
98 
99  default OFFlowAdd oneSwitchReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan,
100  long meterId, long cookie) {
101  return ofFactory.buildFlowAdd()
102  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
103  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
104  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
105  .setBufferId(OFBufferId.NO_BUFFER)
106  .setPriority(DEFAULT_RULE_PRIORITY)
107  .setMatch(ofFactory.buildMatch()
108  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
109  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan))
110  .build())
111  .setInstructions(Arrays.asList(
112  ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
113  ofFactory.instructions().applyActions(Arrays.asList(
114  ofFactory.actions().buildSetField()
115  .setField(ofFactory.oxms().buildVlanVid()
116  .setValue(OFVlanVidMatch.ofVlan(outputVlan))
117  .build())
118  .build(),
119  ofFactory.actions().buildOutput()
120  .setMaxLen(0xFFFFFFFF)
121  .setPort(OFPort.of(outputPort))
122  .build()))
123  .createBuilder()
124  .build()))
125  .setXid(0L)
126  .build();
127  }
128 
129  default OFFlowAdd oneSwitchNoneFlowMod(int inputPort, int outputPort, long meterId, long cookie) {
130  return ofFactory.buildFlowAdd()
131  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
132  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
133  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
134  .setBufferId(OFBufferId.NO_BUFFER)
135  .setPriority(DEFAULT_RULE_PRIORITY)
136  .setMatch(ofFactory.buildMatch()
137  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
138  .build())
139  .setInstructions(Arrays.asList(
140  ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
141  ofFactory.instructions().applyActions(singletonList(
142  ofFactory.actions().buildOutput()
143  .setMaxLen(0xFFFFFFFF)
144  .setPort(OFPort.of(outputPort))
145  .build()))
146  .createBuilder()
147  .build()))
148  .setXid(0L)
149  .build();
150  }
151 
152  default OFFlowAdd oneSwitchPopFlowMod(int inputPort, int outputPort, int inputVlan, long meterId, long cookie) {
153  return ofFactory.buildFlowAdd()
154  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
155  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
156  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
157  .setBufferId(OFBufferId.NO_BUFFER)
158  .setPriority(DEFAULT_RULE_PRIORITY)
159  .setMatch(ofFactory.buildMatch()
160  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
161  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan))
162  .build())
163  .setInstructions(Arrays.asList(
164  ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
165  ofFactory.instructions().applyActions(Arrays.asList(
166  ofFactory.actions().popVlan(),
167  ofFactory.actions().buildOutput()
168  .setMaxLen(0xFFFFFFFF)
169  .setPort(OFPort.of(outputPort))
170  .build()))
171  .createBuilder()
172  .build()))
173  .setXid(0L)
174  .build();
175  }
176 
177  default OFFlowAdd oneSwitchPushFlowMod(int inputPort, int outputPort, int outputVlan, long meterId, long cookie) {
178  return ofFactory.buildFlowAdd()
179  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
180  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
181  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
182  .setBufferId(OFBufferId.NO_BUFFER)
183  .setPriority(DEFAULT_RULE_PRIORITY)
184  .setMatch(ofFactory.buildMatch()
185  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
186  .build())
187  .setInstructions(Arrays.asList(
188  ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
189  ofFactory.instructions().applyActions(Arrays.asList(
190  ofFactory.actions().buildPushVlan()
191  .setEthertype(EthType.of(ETH_TYPE))
192  .build(),
193  ofFactory.actions().buildSetField()
194  .setField(ofFactory.oxms().buildVlanVid()
195  .setValue(OFVlanVidMatch.ofVlan(outputVlan))
196  .build())
197  .build(),
198  ofFactory.actions().buildOutput()
199  .setMaxLen(0xFFFFFFFF)
200  .setPort(OFPort.of(outputPort))
201  .build()))
202  .createBuilder()
203  .build()))
204  .setXid(0L)
205  .build();
206  }
207 
208  default OFMeterMod installMeter(long bandwidth, long burstSize, long meterId) {
209  return ofFactory.buildMeterMod()
210  .setMeterId(meterId)
211  .setCommand(ADD)
212  .setMeters(singletonList(ofFactory.meterBands()
213  .buildDrop()
214  .setRate(bandwidth)
215  .setBurstSize(burstSize).build()))
216  .setFlags(new HashSet<>(Arrays.asList(KBPS, BURST)))
217  .setXid(0L)
218  .build();
219  }
220 }
default OFFlowAdd ingressPopFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie)
OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlanId, int outputVlan, long cookie)
default OFFlowAdd oneSwitchReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long meterId, long cookie)
default OFMeterMod installMeter(long bandwidth, long burstSize, long meterId)
OFFlowAdd ingressNoMatchVlanIdFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie)
OFFlowAdd egressPopFlowMod(int inputPort, int outputPort, int transitVlanId, long cookie)
static final int ETH_TYPE
Definition: Utils.java:85
default OFFlowAdd ingressNoneFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie)
default OFFlowAdd oneSwitchPushFlowMod(int inputPort, int outputPort, int outputVlan, long meterId, long cookie)
default OFFlowAdd oneSwitchNoneFlowMod(int inputPort, int outputPort, long meterId, long cookie)
default OFFlowAdd transitFlowMod(int inputPort, int outputPort, int transitVlan, long cookie)
default OFFlowAdd oneSwitchPopFlowMod(int inputPort, int outputPort, int inputVlan, long meterId, long cookie)
default OFFlowAdd ingressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie)
default OFFlowAdd ingressPushFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie)
OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie)
def build()
Definition: plan-e.py:73
OFFlowAdd egressNoneFlowMod(int inputPort, int outputPort, int transitVlanId, long cookie)
net
Definition: plan-b.py:46
OFFlowAdd egressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long cookie)