alessio | 0af6523 | 2020-09-19 17:06:37 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 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 | * This work was partially supported by EC H2020 project METRO-HAUL (761727). |
| 17 | */ |
| 18 | |
| 19 | package org.onosproject.drivers.odtn; |
| 20 | |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.PortNumber; |
| 23 | import org.onosproject.net.behaviour.InternalConnectivity; |
| 24 | import org.onosproject.net.device.DeviceService; |
| 25 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 26 | |
| 27 | import java.util.Set; |
| 28 | import java.util.stream.Collectors; |
| 29 | |
| 30 | public class FullMeshInternalConnectivity |
| 31 | extends AbstractHandlerBehaviour implements InternalConnectivity { |
| 32 | |
| 33 | /** |
| 34 | * Returnung true for all pairs this implements a device with full connectivity. |
| 35 | * |
| 36 | * @param inputPort in port |
| 37 | * @param outputPort out port |
| 38 | * @return true if connectivity is allowed |
| 39 | */ |
| 40 | @Override |
| 41 | public boolean testConnectivity(PortNumber inputPort, PortNumber outputPort) { |
| 42 | //It is not allowed touse the same port as input and output |
| 43 | if (inputPort.equals(outputPort)) { |
| 44 | return false; |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * To be implemented. |
| 51 | * |
| 52 | * @param inputPort in port |
| 53 | * @return Set of out ports that can be connected to specified in port |
| 54 | */ |
| 55 | @Override |
| 56 | public Set<PortNumber> getOutputPorts(PortNumber inputPort) { |
| 57 | Set<PortNumber> ports; |
| 58 | |
| 59 | //Returns all the device ports, not including input port itself |
| 60 | DeviceService deviceService = this.handler().get(DeviceService.class); |
| 61 | ports = deviceService.getPorts(did()).stream() |
| 62 | .filter(p -> !p.equals(inputPort)) |
| 63 | .map(p -> p.number()) |
| 64 | .collect(Collectors.toSet()); |
| 65 | |
| 66 | return ports; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * To be implemented. |
| 71 | * |
| 72 | * @param outputPort out port |
| 73 | * @return Set of in ports that can be connected to specified out port |
| 74 | */ |
| 75 | @Override |
| 76 | public Set<PortNumber> getInputPorts(PortNumber outputPort) { |
| 77 | Set<PortNumber> ports; |
| 78 | |
| 79 | //Returns all the device ports, not including output port itself |
| 80 | DeviceService deviceService = this.handler().get(DeviceService.class); |
| 81 | ports = deviceService.getPorts(did()).stream() |
| 82 | .filter(p -> !p.equals(outputPort)) |
| 83 | .map(p -> p.number()) |
| 84 | .collect(Collectors.toSet()); |
| 85 | |
| 86 | return ports; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get the deviceId for which the methods apply. |
| 91 | * |
| 92 | * @return The deviceId as contained in the handler data |
| 93 | */ |
| 94 | private DeviceId did() { |
| 95 | return handler().data().deviceId(); |
| 96 | } |
| 97 | } |