HIGUCHI Yuta | 5be3e82 | 2016-05-03 13:51:42 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.optical.device.port; |
| 17 | |
| 18 | import java.util.Optional; |
| 19 | |
| 20 | import org.onosproject.net.Port; |
| 21 | import org.onosproject.net.optical.OtuPort; |
| 22 | import org.onosproject.net.optical.device.OtuPortHelper; |
| 23 | import org.onosproject.net.optical.impl.DefaultOtuPort; |
| 24 | |
| 25 | import com.google.common.annotations.Beta; |
| 26 | |
| 27 | /** |
| 28 | * {@link PortMapper} to handler {@link OtuPort} translation. |
| 29 | */ |
| 30 | @Beta |
| 31 | public class OtuPortMapper extends AbstractPortMapper<OtuPort> { |
| 32 | |
| 33 | @Override |
| 34 | public boolean is(Port port) { |
| 35 | return port != null && |
| 36 | port.type() == Port.Type.OTU && |
| 37 | super.is(port); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public Optional<OtuPort> as(Port port) { |
| 42 | if (port instanceof OtuPort) { |
| 43 | return Optional.of((OtuPort) port); |
| 44 | } |
| 45 | return super.as(port); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected Optional<OtuPort> mapPort(Port port) { |
| 50 | if (port instanceof OtuPort) { |
| 51 | return Optional.of((OtuPort) port); |
| 52 | } else if (port instanceof org.onosproject.net.OtuPort) { |
| 53 | // TODO remove after deprecation of old OtuPort is complete |
| 54 | |
| 55 | // translate to new OtuPort |
| 56 | org.onosproject.net.OtuPort old = (org.onosproject.net.OtuPort) port; |
| 57 | return Optional.of(new DefaultOtuPort(old, |
| 58 | old.signalType())); |
| 59 | } |
| 60 | |
| 61 | return OtuPortHelper.asOtuPort(port); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | } |