Open Kilda Java Documentation
PushSchemeOutputCommands.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 
23 import net.floodlightcontroller.util.FlowModUtils;
24 import org.projectfloodlight.openflow.protocol.OFFlowAdd;
25 import org.projectfloodlight.openflow.protocol.match.MatchField;
26 import org.projectfloodlight.openflow.types.EthType;
27 import org.projectfloodlight.openflow.types.OFBufferId;
28 import org.projectfloodlight.openflow.types.OFPort;
29 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
30 import org.projectfloodlight.openflow.types.U64;
31 
32 import java.util.Arrays;
33 
38 public class PushSchemeOutputCommands implements OutputCommands {
39  @Override
40  public OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan,
41  long meterId, long cookie) {
42  return ofFactory.buildFlowAdd()
43  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
44  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
45  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
46  .setBufferId(OFBufferId.NO_BUFFER)
47  .setPriority(DEFAULT_RULE_PRIORITY)
48  .setMatch(ofFactory.buildMatch()
49  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
50  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan))
51  .build())
52  .setInstructions(Arrays.asList(
53  ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
54  ofFactory.instructions().applyActions(Arrays.asList(
55  ofFactory.actions().buildPushVlan()
56  .setEthertype(EthType.of(ETH_TYPE))
57  .build(),
58  ofFactory.actions().buildSetField()
59  .setField(ofFactory.oxms().buildVlanVid()
60  .setValue(OFVlanVidMatch.ofVlan(transitVlan))
61  .build())
62  .build(),
63  ofFactory.actions().buildOutput()
64  .setMaxLen(0xFFFFFFFF)
65  .setPort(OFPort.of(outputPort))
66  .build()))
67  .createBuilder()
68  .build()))
69  .setXid(0L)
70  .build();
71 
72  }
73 
74  @Override
75  public OFFlowAdd ingressNoMatchVlanIdFlowMod(int inputPort, int outputPort, int transitVlan,
76  long meterId, 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  .build())
86  .setInstructions(Arrays.asList(
87  ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
88  ofFactory.instructions().applyActions(Arrays.asList(
89  ofFactory.actions().buildPushVlan()
90  .setEthertype(EthType.of(ETH_TYPE))
91  .build(),
92  ofFactory.actions().buildSetField()
93  .setField(ofFactory.oxms().buildVlanVid()
94  .setValue(OFVlanVidMatch.ofVlan(transitVlan))
95  .build())
96  .build(),
97  ofFactory.actions().buildOutput()
98  .setMaxLen(0xFFFFFFFF)
99  .setPort(OFPort.of(outputPort))
100  .build()))
101  .createBuilder()
102  .build()))
103  .setXid(0L)
104  .build();
105 
106  }
107 
108  @Override
109  public OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlan, int outputVlan, long cookie) {
110  return ofFactory.buildFlowAdd()
111  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
112  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
113  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
114  .setBufferId(OFBufferId.NO_BUFFER)
115  .setPriority(DEFAULT_RULE_PRIORITY)
116  .setMatch(ofFactory.buildMatch()
117  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
118  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan))
119  .build())
120  .setInstructions(singletonList(
121  ofFactory.instructions().applyActions(Arrays.asList(
122  ofFactory.actions().popVlan(),
123  ofFactory.actions().buildPushVlan()
124  .setEthertype(EthType.of(ETH_TYPE))
125  .build(),
126  ofFactory.actions().buildSetField()
127  .setField(ofFactory.oxms().buildVlanVid()
128  .setValue(OFVlanVidMatch.ofVlan(outputVlan))
129  .build())
130  .build(),
131  ofFactory.actions().buildOutput()
132  .setMaxLen(0xFFFFFFFF)
133  .setPort(OFPort.of(outputPort))
134  .build()))
135  .createBuilder()
136  .build()))
137  .setXid(0L)
138  .build();
139  }
140 
141  @Override
142  public OFFlowAdd egressPopFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) {
143  return ofFactory.buildFlowAdd()
144  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
145  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
146  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
147  .setBufferId(OFBufferId.NO_BUFFER)
148  .setPriority(DEFAULT_RULE_PRIORITY)
149  .setMatch(ofFactory.buildMatch()
150  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
151  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan))
152  .build())
153  .setInstructions(singletonList(
154  ofFactory.instructions().applyActions(Arrays.asList(
155  ofFactory.actions().popVlan(),
156  ofFactory.actions().popVlan(),
157  ofFactory.actions().buildOutput()
158  .setMaxLen(0xFFFFFFFF)
159  .setPort(OFPort.of(outputPort))
160  .build()))
161  .createBuilder()
162  .build()))
163  .setXid(0L)
164  .build();
165  }
166 
167  @Override
168  public OFFlowAdd egressNoneFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) {
169  return ofFactory.buildFlowAdd()
170  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
171  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
172  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
173  .setBufferId(OFBufferId.NO_BUFFER)
174  .setPriority(DEFAULT_RULE_PRIORITY)
175  .setMatch(ofFactory.buildMatch()
176  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
177  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan))
178  .build())
179  .setInstructions(singletonList(
180  ofFactory.instructions().applyActions(Arrays.asList(
181  ofFactory.actions().popVlan(),
182  ofFactory.actions().buildOutput()
183  .setMaxLen(0xFFFFFFFF)
184  .setPort(OFPort.of(outputPort))
185  .build()))
186  .createBuilder()
187  .build()))
188  .setXid(0L)
189  .build();
190  }
191 
192  @Override
193  public OFFlowAdd egressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long cookie) {
194  return ofFactory.buildFlowAdd()
195  .setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
196  .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
197  .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
198  .setBufferId(OFBufferId.NO_BUFFER)
199  .setPriority(DEFAULT_RULE_PRIORITY)
200  .setMatch(ofFactory.buildMatch()
201  .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
202  .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan))
203  .build())
204  .setInstructions(singletonList(
205  ofFactory.instructions().applyActions(Arrays.asList(
206  ofFactory.actions().popVlan(),
207  ofFactory.actions().buildSetField()
208  .setField(ofFactory.oxms().buildVlanVid()
209  .setValue(OFVlanVidMatch.ofVlan(outputVlan))
210  .build())
211  .build(),
212  ofFactory.actions().buildOutput()
213  .setMaxLen(0xFFFFFFFF)
214  .setPort(OFPort.of(outputPort))
215  .build()))
216  .createBuilder()
217  .build()))
218  .setXid(0L)
219  .build();
220  }
221 }
OFFlowAdd egressPopFlowMod(int inputPort, int outputPort, int transitVlan, long cookie)
OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie)
static final int ETH_TYPE
Definition: Utils.java:85
OFFlowAdd egressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long cookie)
OFFlowAdd egressNoneFlowMod(int inputPort, int outputPort, int transitVlan, long cookie)
OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlan, int outputVlan, long cookie)
OFFlowAdd ingressNoMatchVlanIdFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie)
def build()
Definition: plan-e.py:73
net
Definition: plan-b.py:46