Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 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 | |
Ray Milkey | facf286 | 2017-08-03 11:58:29 -0700 | [diff] [blame] | 17 | package org.onosproject.net.intf; |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 18 | |
Ray Milkey | facf286 | 2017-08-03 11:58:29 -0700 | [diff] [blame] | 19 | import java.util.Set; |
| 20 | |
Charles Chan | 971d7ba | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Charles Chan | 8464592 | 2018-05-01 16:21:50 -0700 | [diff] [blame] | 22 | import org.apache.commons.lang.NotImplementedException; |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.VlanId; |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 25 | import org.onosproject.event.ListenerService; |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 26 | import org.onosproject.net.ConnectPoint; |
| 27 | |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Service for interacting with interfaces. |
| 30 | */ |
Ray Milkey | facf286 | 2017-08-03 11:58:29 -0700 | [diff] [blame] | 31 | |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 32 | public interface InterfaceService |
| 33 | extends ListenerService<InterfaceEvent, InterfaceListener> { |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Returns the set of all interfaces in the system. |
| 37 | * |
| 38 | * @return set of interfaces |
| 39 | */ |
| 40 | Set<Interface> getInterfaces(); |
| 41 | |
| 42 | /** |
Jonathan Hart | 43d232e | 2016-02-03 15:34:10 -0800 | [diff] [blame] | 43 | * Returns the interface with the given name. |
| 44 | * |
| 45 | * @param connectPoint connect point of the interface |
| 46 | * @param name name of the interface |
| 47 | * @return interface if it exists, otherwise null |
| 48 | */ |
| 49 | Interface getInterfaceByName(ConnectPoint connectPoint, String name); |
| 50 | |
| 51 | /** |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 52 | * Returns the set of interfaces configured on the given port. |
| 53 | * |
| 54 | * @param port connect point |
| 55 | * @return set of interfaces |
| 56 | */ |
| 57 | Set<Interface> getInterfacesByPort(ConnectPoint port); |
| 58 | |
| 59 | /** |
| 60 | * Returns the set of interfaces with the given IP address. |
| 61 | * |
| 62 | * @param ip IP address |
| 63 | * @return set of interfaces |
| 64 | */ |
| 65 | Set<Interface> getInterfacesByIp(IpAddress ip); |
| 66 | |
| 67 | /** |
| 68 | * Returns the set of interfaces in the given VLAN. |
| 69 | * |
| 70 | * @param vlan VLAN ID of the interfaces |
| 71 | * @return set of interfaces |
| 72 | */ |
| 73 | Set<Interface> getInterfacesByVlan(VlanId vlan); |
| 74 | |
| 75 | /** |
| 76 | * Returns an interface that has an address that is in the same subnet as |
| 77 | * the given IP address. |
| 78 | * |
| 79 | * @param ip IP address to find matching subnet interface for |
| 80 | * @return interface |
| 81 | */ |
| 82 | Interface getMatchingInterface(IpAddress ip); |
Charles Chan | b3b09cd | 2017-03-14 12:53:46 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Returns all interfaces that have an address that is in the same |
| 86 | * subnet as the given IP address. |
| 87 | * |
| 88 | * @param ip IP address to find matching subnet interface for |
| 89 | * @return a set of interfaces |
| 90 | */ |
| 91 | Set<Interface> getMatchingInterfaces(IpAddress ip); |
Charles Chan | 971d7ba | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Returns untagged VLAN configured on given connect point. |
| 95 | * <p> |
| 96 | * Only returns the first match if there are multiple untagged VLAN configured |
| 97 | * on the connect point. |
| 98 | * |
| 99 | * @param connectPoint connect point |
| 100 | * @return untagged VLAN or null if not configured |
| 101 | */ |
| 102 | default VlanId getUntaggedVlanId(ConnectPoint connectPoint) { |
| 103 | return null; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Returns tagged VLAN configured on given connect point. |
| 108 | * <p> |
| 109 | * Returns all matches if there are multiple tagged VLAN configured |
| 110 | * on the connect point. |
| 111 | * |
| 112 | * @param connectPoint connect point |
| 113 | * @return tagged VLAN or empty set if not configured |
| 114 | */ |
| 115 | default Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) { |
| 116 | return ImmutableSet.of(); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Returns native VLAN configured on given connect point. |
| 121 | * <p> |
| 122 | * Only returns the first match if there are multiple native VLAN configured |
| 123 | * on the connect point. |
| 124 | * |
| 125 | * @param connectPoint connect point |
| 126 | * @return native VLAN or null if not configured |
| 127 | */ |
| 128 | default VlanId getNativeVlanId(ConnectPoint connectPoint) { |
| 129 | return null; |
| 130 | } |
Saurav Das | 9a55429 | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Returns true if given connectPoint has an IP address or vlan configured |
| 134 | * on any of its interfaces. |
| 135 | * |
| 136 | * @param connectPoint the port on a device |
| 137 | * @return true if connectpoint has a configured interface |
| 138 | */ |
Charles Chan | 8464592 | 2018-05-01 16:21:50 -0700 | [diff] [blame] | 139 | default boolean isConfigured(ConnectPoint connectPoint) { |
| 140 | throw new NotImplementedException("isConfigured is not implemented"); |
| 141 | } |
Saurav Das | 09c2c4d | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Returns true if given vlanId is in use due to configuration on any of the |
| 145 | * interfaces in the system. |
| 146 | * |
| 147 | * @param vlanId the vlan id being queried |
| 148 | * @return true if vlan is configured on any interface |
| 149 | */ |
| 150 | default boolean inUse(VlanId vlanId) { |
| 151 | throw new NotImplementedException("isConfigured is not implemented"); |
| 152 | } |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 153 | } |