blob: eb31a5ede9ec25896fe01b5ad6ec3eafa28c690b [file] [log] [blame]
Jimmy Yanda878fc2016-09-02 16:32:01 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jimmy Yanda878fc2016-09-02 16:32:01 -07003 *
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.roadm;
17
18import org.onosproject.net.OchSignal;
19import org.onosproject.net.PortNumber;
20import org.onosproject.net.flow.FlowRule;
21import org.onosproject.net.flow.criteria.Criterion;
22import org.onosproject.net.flow.criteria.OchSignalCriterion;
23import org.onosproject.net.flow.criteria.PortCriterion;
24import org.onosproject.net.flow.instructions.Instruction;
25import org.onosproject.net.flow.instructions.Instructions;
26
27import static com.google.common.base.Preconditions.checkNotNull;
28
29import java.util.List;
30
31/**
32 * Representation of an internal ROADM connection.
33 */
34public final class ChannelData {
35 private PortNumber inPort;
36 private PortNumber outPort;
37 private OchSignal ochSignal;
38
39 private ChannelData(PortNumber inPort, PortNumber outPort, OchSignal ochSignal) {
40 this.inPort = inPort;
41 this.outPort = outPort;
42 this.ochSignal = ochSignal;
43 }
44
45 /**
46 * Returns a ChannelData representation from a flow rule. The rule must contain
47 * a Criterion.Type.IN_PORT selector, Criterion.Type.OCH_SIGID selector, and
48 * Instruction.Type.OUTPUT instruction.
49 *
50 * @param rule the flow rule representing the connection
51 * @return ChannelData representation of the connection
52 */
53 public static ChannelData fromFlow(FlowRule rule) {
54 checkNotNull(rule);
55
56 Criterion in = rule.selector().getCriterion(Criterion.Type.IN_PORT);
57 checkNotNull(in);
58 PortNumber inPort = ((PortCriterion) in).port();
59
60 Criterion och = rule.selector().getCriterion(Criterion.Type.OCH_SIGID);
MaoLu937cf422017-03-03 23:31:46 -080061 OchSignal ochSignal = och == null ? null : ((OchSignalCriterion) och).lambda();
Jimmy Yanda878fc2016-09-02 16:32:01 -070062
63 PortNumber outPort = null;
64 List<Instruction> instructions = rule.treatment().allInstructions();
65 for (Instruction ins : instructions) {
66 if (ins.type() == Instruction.Type.OUTPUT) {
67 outPort = ((Instructions.OutputInstruction) ins).port();
68 }
69 }
70 checkNotNull(outPort);
71
72 return new ChannelData(inPort, outPort, ochSignal);
73 }
74
75 /**
76 * Returns the input port.
77 *
78 * @return input port
79 */
80 public PortNumber inPort() {
81 return inPort;
82 }
83
84 /**
85 * Returns the output port.
86 *
87 * @return output port
88 */
89 public PortNumber outPort() {
90 return outPort;
91 }
92
93 /**
94 * Returns the channel signal.
95 *
96 * @return channel signal
97 */
98 public OchSignal ochSignal() {
99 return ochSignal;
100 }
101}