blob: 70a8aa9a28c14f650f6cff4e3508a1f78f7c955c [file] [log] [blame]
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -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.net.optical.device.port;
17
18import java.util.Optional;
19
20import org.onosproject.net.Port;
21import org.onosproject.net.optical.OmsPort;
22import org.onosproject.net.optical.device.OmsPortHelper;
23import org.onosproject.net.optical.impl.DefaultOmsPort;
24
25import com.google.common.annotations.Beta;
26
27/**
28 * {@link PortMapper} to handler {@link OmsPort} translation.
29 */
30@Beta
31public class OmsPortMapper extends AbstractPortMapper<OmsPort> {
32
33 @Override
34 public boolean is(Port port) {
35 return port != null &&
36 port.type() == Port.Type.OMS &&
37 super.is(port);
38 }
39
40 @Override
41 public Optional<OmsPort> as(Port port) {
42 if (port instanceof OmsPort) {
43 return Optional.of((OmsPort) port);
44 }
45 return super.as(port);
46 }
47
48 @Override
49 protected Optional<OmsPort> mapPort(Port port) {
50 if (port instanceof OmsPort) {
51 return Optional.of((OmsPort) port);
52 } else if (port instanceof org.onosproject.net.OmsPort) {
53 // TODO remove after deprecation of old OmsPort is complete
54
55 // translate to new OmsPort
56 org.onosproject.net.OmsPort old = (org.onosproject.net.OmsPort) port;
57 return Optional.of(new DefaultOmsPort(old,
58 old.minFrequency(),
59 old.maxFrequency(),
60 old.grid()));
61 }
62
63 return OmsPortHelper.asOmsPort(port);
64 }
65
66}