blob: 07c6c41c1cc904d1edcad3799d635ba925513c35 [file] [log] [blame]
Jimmy Yanda878fc2016-09-02 16:32:01 -07001/*
2 * Copyright 2016-present 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.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);
61 checkNotNull(och);
62 OchSignal ochSignal = ((OchSignalCriterion) och).lambda();
63
64 PortNumber outPort = null;
65 List<Instruction> instructions = rule.treatment().allInstructions();
66 for (Instruction ins : instructions) {
67 if (ins.type() == Instruction.Type.OUTPUT) {
68 outPort = ((Instructions.OutputInstruction) ins).port();
69 }
70 }
71 checkNotNull(outPort);
72
73 return new ChannelData(inPort, outPort, ochSignal);
74 }
75
76 /**
77 * Returns the input port.
78 *
79 * @return input port
80 */
81 public PortNumber inPort() {
82 return inPort;
83 }
84
85 /**
86 * Returns the output port.
87 *
88 * @return output port
89 */
90 public PortNumber outPort() {
91 return outPort;
92 }
93
94 /**
95 * Returns the channel signal.
96 *
97 * @return channel signal
98 */
99 public OchSignal ochSignal() {
100 return ochSignal;
101 }
102}