diff options
author | 2015-09-09 22:15:21 -0700 | |
---|---|---|
committer | 2015-09-09 22:15:21 -0700 | |
commit | 13d05bc8458758ee39cb829098241e89616717ee (patch) | |
tree | 22a4d1ce65f15952f07a3df5af4b462b4697cb3a /framework/src/onos/core/api/src/main/java/org/onosproject/net/host | |
parent | 6139282e1e93c2322076de4b91b1c85d0bc4a8b3 (diff) |
ONOS checkin based on commit tag e796610b1f721d02f9b0e213cf6f7790c10ecd60
Change-Id: Ife8810491034fe7becdba75dda20de4267bd15cd
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org/onosproject/net/host')
14 files changed, 1123 insertions, 0 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java new file mode 100644 index 00000000..1f05197a --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java @@ -0,0 +1,122 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import java.util.Collections; +import java.util.Set; + +import org.onosproject.net.AbstractDescription; +import org.onosproject.net.HostLocation; +import org.onosproject.net.SparseAnnotations; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; + +import com.google.common.collect.ImmutableSet; + +import static com.google.common.base.MoreObjects.toStringHelper; + +/** + * Default implementation of an immutable host description. + */ +public class DefaultHostDescription extends AbstractDescription + implements HostDescription { + + private final MacAddress mac; + private final VlanId vlan; + private final HostLocation location; + private final Set<IpAddress> ip; + + /** + * Creates a host description using the supplied information. + * + * @param mac host MAC address + * @param vlan host VLAN identifier + * @param location host location + * @param annotations optional key/value annotations map + */ + public DefaultHostDescription(MacAddress mac, VlanId vlan, + HostLocation location, + SparseAnnotations... annotations) { + this(mac, vlan, location, Collections.<IpAddress>emptySet(), + annotations); + } + + /** + * Creates a host description using the supplied information. + * + * @param mac host MAC address + * @param vlan host VLAN identifier + * @param location host location + * @param ip host IP address + * @param annotations optional key/value annotations map + */ + public DefaultHostDescription(MacAddress mac, VlanId vlan, + HostLocation location, IpAddress ip, + SparseAnnotations... annotations) { + this(mac, vlan, location, ImmutableSet.of(ip), annotations); + } + + /** + * Creates a host description using the supplied information. + * + * @param mac host MAC address + * @param vlan host VLAN identifier + * @param location host location + * @param ip host IP addresses + * @param annotations optional key/value annotations map + */ + public DefaultHostDescription(MacAddress mac, VlanId vlan, + HostLocation location, Set<IpAddress> ip, + SparseAnnotations... annotations) { + super(annotations); + this.mac = mac; + this.vlan = vlan; + this.location = location; + this.ip = ImmutableSet.copyOf(ip); + } + + @Override + public MacAddress hwAddress() { + return mac; + } + + @Override + public VlanId vlan() { + return vlan; + } + + @Override + public HostLocation location() { + return location; + } + + @Override + public Set<IpAddress> ipAddress() { + return ip; + } + + @Override + public String toString() { + return toStringHelper(this) + .add("mac", mac) + .add("vlan", vlan) + .add("location", location) + .add("ipAddress", ip) + .toString(); + } + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostAdminService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostAdminService.java new file mode 100644 index 00000000..d620fedb --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostAdminService.java @@ -0,0 +1,66 @@ +/* + * Copyright 2014-2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.HostId; + +/** + * Service for administering the inventory of end-station hosts. + */ +public interface HostAdminService extends HostService { + + /** + * Removes the end-station host with the specified identifier. + * + * @param hostId host identifier + */ + void removeHost(HostId hostId); + + /** + * Binds IP and MAC addresses to the given connection point. + * <p> + * The addresses are added to the set of addresses already bound to the + * connection point. + * + * @param addresses address object containing addresses to add and the port + * to add them to + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + void bindAddressesToPort(PortAddresses addresses); + + /** + * Removes the addresses contained in the given PortAddresses object from + * the set of addresses bound to the port. + * + * @param portAddresses set of addresses to remove and port to remove them + * from + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + void unbindAddressesFromPort(PortAddresses portAddresses); + + /** + * Removes all address information for the given connection point. + * + * @param connectPoint the connection point to remove address information + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + void clearAddresses(ConnectPoint connectPoint); + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostDescription.java new file mode 100644 index 00000000..14c6f7ad --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostDescription.java @@ -0,0 +1,58 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import java.util.Set; + +import org.onosproject.net.Description; +import org.onosproject.net.HostLocation; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; + +/** + * Information describing host and its location. + */ +public interface HostDescription extends Description { + + /** + * Returns the MAC address associated with this host (NIC). + * + * @return the MAC address of this host + */ + MacAddress hwAddress(); + + /** + * Returns the VLAN associated with this host. + * + * @return the VLAN ID value + */ + VlanId vlan(); + + /** + * Returns the location of the host on the network edge. + * + * @return the network location + */ + HostLocation location(); + + /** + * Returns the IP address associated with this host's MAC. + * + * @return host IP address + */ + Set<IpAddress> ipAddress(); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java new file mode 100644 index 00000000..98329df0 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java @@ -0,0 +1,73 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onosproject.event.AbstractEvent; +import org.onosproject.net.Host; + +/** + * Describes end-station host event. + */ +public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { + + /** + * Type of host events. + */ + public enum Type { + /** + * Signifies that a new host has been detected. + */ + HOST_ADDED, + + /** + * Signifies that a host has been removed. + */ + HOST_REMOVED, + + /** + * Signifies that host data changed, e.g. IP address + */ + HOST_UPDATED, + + /** + * Signifies that a host location has changed. + */ + HOST_MOVED + } + + /** + * Creates an event of a given type and for the specified host and the + * current time. + * + * @param type host event type + * @param host event host subject + */ + public HostEvent(Type type, Host host) { + super(type, host); + } + + /** + * Creates an event of a given type and for the specified host and time. + * + * @param type host event type + * @param host event host subject + * @param time occurrence time + */ + public HostEvent(Type type, Host host, long time) { + super(type, host, time); + } + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostListener.java new file mode 100644 index 00000000..2eef7592 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostListener.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onosproject.event.EventListener; + +/** + * Entity capable of receiving end-station host related events. + */ +public interface HostListener extends EventListener<HostEvent> { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProvider.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProvider.java new file mode 100644 index 00000000..0270996b --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onosproject.net.Host; +import org.onosproject.net.provider.Provider; + +/** + * Provider of information about hosts and their location on the network. + */ +public interface HostProvider extends Provider { + + /** + * Triggers an asynchronous probe of the specified host, intended to + * determine whether the host is present or not. An indirect result of this + * should be invocation of {@link org.onosproject.net.host.HostProviderService#hostDetected} + * or {@link org.onosproject.net.host.HostProviderService#hostVanished} + * at some later point in time. + * + * @param host host to probe + */ + void triggerProbe(Host host); + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProviderRegistry.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProviderRegistry.java new file mode 100644 index 00000000..8ab600c2 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProviderRegistry.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onosproject.net.provider.ProviderRegistry; + +/** + * Abstraction of a host provider registry. + */ +public interface HostProviderRegistry + extends ProviderRegistry<HostProvider, HostProviderService> { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProviderService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProviderService.java new file mode 100644 index 00000000..8678a297 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostProviderService.java @@ -0,0 +1,42 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onosproject.net.HostId; +import org.onosproject.net.provider.ProviderService; + +/** + * Means of conveying host information to the core. + */ +public interface HostProviderService extends ProviderService<HostProvider> { + + /** + * Notifies the core when a host has been detected on a network along with + * information that identifies the host location. + * + * @param hostId id of the host that been detected + * @param hostDescription description of host and its location + */ + void hostDetected(HostId hostId, HostDescription hostDescription); + + /** + * Notifies the core when a host is no longer detected on a network. + * + * @param hostId id of the host that vanished + */ + void hostVanished(HostId hostId); + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostService.java new file mode 100644 index 00000000..be114f05 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostService.java @@ -0,0 +1,146 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; +import org.onosproject.event.ListenerService; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.DeviceId; +import org.onosproject.net.Host; +import org.onosproject.net.HostId; + +import java.util.Set; + +/** + * Service for interacting with the inventory of end-station hosts. + */ +public interface HostService + extends ListenerService<HostEvent, HostListener> { + + /** + * Returns the number of end-station hosts known to the system. + * + * @return number of end-station hosts + */ + int getHostCount(); + + /** + * Returns a collection of all end-station hosts. + * + * @return collection of hosts + */ + Iterable<Host> getHosts(); + + /** + * Returns the host with the specified identifier. + * + * @param hostId host identifier + * @return host or null if one with the given identifier is not known + */ + Host getHost(HostId hostId); + + /** + * Returns the set of hosts that belong to the specified VLAN. + * + * @param vlanId vlan identifier + * @return set of hosts in the given vlan id + */ + Set<Host> getHostsByVlan(VlanId vlanId); + + /** + * Returns the set of hosts that have the specified MAC address. + * + * @param mac mac address + * @return set of hosts with the given mac + */ + Set<Host> getHostsByMac(MacAddress mac); + + /** + * Returns the set of hosts that have the specified IP address. + * + * @param ip ip address + * @return set of hosts with the given IP + */ + Set<Host> getHostsByIp(IpAddress ip); + + // TODO: consider adding Host getHostByIp(IpAddress ip, VlanId vlan); + + /** + * Returns the set of hosts whose most recent location is the specified + * connection point. + * + * @param connectPoint connection point + * @return set of hosts connected to the connection point + */ + Set<Host> getConnectedHosts(ConnectPoint connectPoint); + + /** + * Returns the set of hosts whose most recent location is the specified + * infrastructure device. + * + * @param deviceId device identifier + * @return set of hosts connected to the device + */ + Set<Host> getConnectedHosts(DeviceId deviceId); + + /** + * Requests the host service to monitor hosts with the given IP address and + * notify listeners of changes. + * + * @param ip IP address of the host to monitor + */ + void startMonitoringIp(IpAddress ip); + + /** + * Stops the host service from monitoring an IP address. + * + * @param ip IP address to stop monitoring + */ + // TODO clients can cancel other client's requests + void stopMonitoringIp(IpAddress ip); + + /** + * Requests the host service to resolve the MAC address for the given IP + * address. This will trigger a notification to the host listeners if the MAC + * address is found. + * + * @param ip IP address to find the MAC address for + */ + void requestMac(IpAddress ip); + + /** + * Returns the addresses information for all connection points. + * + * @return the set of address bindings for all connection points + * @deprecated in Drake release: use InterfaceService instead + */ + @Deprecated + Set<PortAddresses> getAddressBindings(); + + /** + * Retrieves the addresses that have been bound to the given connection + * point. + * + * @param connectPoint the connection point to retrieve address bindings for + * @return addresses bound to the port + * @deprecated in Drake release: use InterfaceService instead + */ + @Deprecated + Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint); + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostStore.java new file mode 100644 index 00000000..ca11a942 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostStore.java @@ -0,0 +1,167 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.DeviceId; +import org.onosproject.net.Host; +import org.onosproject.net.HostId; +import org.onosproject.net.provider.ProviderId; +import org.onosproject.store.Store; + +import java.util.Set; + +/** + * Manages inventory of end-station hosts; not intended for direct use. + */ +public interface HostStore extends Store<HostEvent, HostStoreDelegate> { + + /** + * Creates a new host or updates the existing one based on the specified + * description. + * + * @param providerId provider identification + * @param hostId host identification + * @param hostDescription host description data + * @return appropriate event or null if no change resulted + */ + HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, + HostDescription hostDescription); + + // FIXME: API to remove only IpAddress is missing + /** + * Removes the specified host from the inventory. + * + * @param hostId host identification + * @return remove event or null if host was not found + */ + HostEvent removeHost(HostId hostId); + + /** + * Returns the number of hosts in the store. + * + * @return host count + */ + int getHostCount(); + + /** + * Returns a collection of all hosts in the store. + * + * @return iterable collection of all hosts + */ + Iterable<Host> getHosts(); + + /** + * Returns the host with the specified identifer. + * + * @param hostId host identification + * @return host or null if not found + */ + Host getHost(HostId hostId); + + /** + * Returns the set of all hosts within the specified VLAN. + * + * @param vlanId vlan id + * @return set of hosts in the vlan + */ + Set<Host> getHosts(VlanId vlanId); + + /** + * Returns the set of hosts with the specified MAC address. + * + * @param mac mac address + * @return set of hosts with the given mac + */ + Set<Host> getHosts(MacAddress mac); + + /** + * Returns the set of hosts with the specified IP address. + * + * @param ip ip address + * @return set of hosts with the given IP + */ + Set<Host> getHosts(IpAddress ip); + + /** + * Returns the set of hosts whose location falls on the given connection point. + * + * @param connectPoint connection point + * @return set of hosts + */ + Set<Host> getConnectedHosts(ConnectPoint connectPoint); + + /** + * Returns the set of hosts whose location falls on the given device. + * + * @param deviceId infrastructure device identifier + * @return set of hosts + */ + Set<Host> getConnectedHosts(DeviceId deviceId); + + /** + * Updates the address information for a given port. The given address + * information is added to any previously held information for the port. + * + * @param addresses the port and address information + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + void updateAddressBindings(PortAddresses addresses); + + /** + * Removes the given addresses from the set of address information held for + * a port. + * + * @param addresses the port and address information + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + void removeAddressBindings(PortAddresses addresses); + + /** + * Removes any previously stored address information for a given connection + * point. + * + * @param connectPoint the connection point + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + void clearAddressBindings(ConnectPoint connectPoint); + + /** + * Returns the address bindings stored for all connection points. + * + * @return the set of address bindings + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + Set<PortAddresses> getAddressBindings(); + + /** + * Returns the address bindings for a particular connection point. + * + * @param connectPoint the connection point to return address information + * for + * @return address information for the connection point + * @deprecated in Drake release: address info now stored in InterfaceService + */ + @Deprecated + Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostStoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostStoreDelegate.java new file mode 100644 index 00000000..efc84232 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostStoreDelegate.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onosproject.store.StoreDelegate; + +/** + * Infrastructure link store delegate abstraction. + */ +public interface HostStoreDelegate extends StoreDelegate<HostEvent> { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/InterfaceIpAddress.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/InterfaceIpAddress.java new file mode 100644 index 00000000..2f53df50 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/InterfaceIpAddress.java @@ -0,0 +1,192 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.IpPrefix; + +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Represents a single IP address information on an interface. + * + * TODO: + * - Add computation for the default broadcast address if it is not + * specified + * - Add explicit checks that each IP address or prefix belong to the + * same IP version: IPv4/IPv6. + * - Inside the copy constructor we should use copy constructors for each + * field + */ +public class InterfaceIpAddress { + private final IpAddress ipAddress; + private final IpPrefix subnetAddress; + private final IpAddress broadcastAddress; + private final IpAddress peerAddress; + + /** + * Copy constructor. + * + * @param other the object to copy from + */ + public InterfaceIpAddress(InterfaceIpAddress other) { + // TODO: we should use copy constructors for each field + this.ipAddress = other.ipAddress; + this.subnetAddress = other.subnetAddress; + this.broadcastAddress = other.broadcastAddress; + this.peerAddress = other.peerAddress; + } + + /** + * Constructor for a given IP address and a subnet address. + * + * @param ipAddress the IP address + * @param subnetAddress the IP subnet address + */ + public InterfaceIpAddress(IpAddress ipAddress, IpPrefix subnetAddress) { + this.ipAddress = checkNotNull(ipAddress); + this.subnetAddress = checkNotNull(subnetAddress); + // TODO: Recompute the default broadcast address from the subnet + // address + this.broadcastAddress = null; + this.peerAddress = null; + } + + /** + * Constructor for a given IP address and a subnet address. + * + * @param ipAddress the IP address + * @param subnetAddress the IP subnet address + * @param broadcastAddress the IP broadcast address. It can be used + * to specify non-default broadcast address + */ + public InterfaceIpAddress(IpAddress ipAddress, IpPrefix subnetAddress, + IpAddress broadcastAddress) { + this.ipAddress = checkNotNull(ipAddress); + this.subnetAddress = checkNotNull(subnetAddress); + this.broadcastAddress = broadcastAddress; + this.peerAddress = null; + } + + /** + * Constructor for a given IP address and a subnet address. + * + * @param ipAddress the IP address + * @param subnetAddress the IP subnet address + * @param broadcastAddress the IP broadcast address. It can be used + * to specify non-default broadcast address. It should be null for + * point-to-point interfaces with a peer address + * @param peerAddress the peer IP address for point-to-point interfaces + */ + public InterfaceIpAddress(IpAddress ipAddress, IpPrefix subnetAddress, + IpAddress broadcastAddress, + IpAddress peerAddress) { + this.ipAddress = checkNotNull(ipAddress); + this.subnetAddress = checkNotNull(subnetAddress); + this.broadcastAddress = broadcastAddress; + this.peerAddress = peerAddress; + } + + /** + * Gets the IP address. + * + * @return the IP address + */ + public IpAddress ipAddress() { + return ipAddress; + } + + /** + * Gets the IP subnet address. + * + * @return the IP subnet address + */ + public IpPrefix subnetAddress() { + return subnetAddress; + } + + /** + * Gets the subnet IP broadcast address. + * + * @return the subnet IP broadcast address + */ + public IpAddress broadcastAddress() { + return broadcastAddress; + } + + /** + * Gets the IP point-to-point interface peer address. + * + * @return the IP point-to-point interface peer address + */ + public IpAddress peerAddress() { + return peerAddress; + } + + /** + * Converts a CIDR string literal to an interface IP address. + * E.g. 10.0.0.1/24 + * + * @param value an IP address value in string form + * @return an interface IP address + * @throws IllegalArgumentException if the argument is invalid + */ + public static InterfaceIpAddress valueOf(String value) { + String[] splits = value.split("/"); + checkArgument(splits.length == 2, "Invalid IP address and prefix length format"); + + // NOTE: IpPrefix will mask-out the bits after the prefix length. + IpPrefix subnet = IpPrefix.valueOf(value); + IpAddress addr = IpAddress.valueOf(splits[0]); + return new InterfaceIpAddress(addr, subnet); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof InterfaceIpAddress)) { + return false; + } + InterfaceIpAddress otherAddr = (InterfaceIpAddress) other; + + return Objects.equals(this.ipAddress, otherAddr.ipAddress) + && Objects.equals(this.subnetAddress, otherAddr.subnetAddress) + && Objects.equals(this.broadcastAddress, + otherAddr.broadcastAddress) + && Objects.equals(this.peerAddress, otherAddr.peerAddress); + } + + @Override + public int hashCode() { + return Objects.hash(ipAddress, subnetAddress, broadcastAddress, + peerAddress); + } + + @Override + public String toString() { + /*return toStringHelper(this).add("ipAddress", ipAddress) + .add("subnetAddress", subnetAddress) + .add("broadcastAddress", broadcastAddress) + .add("peerAddress", peerAddress) + .omitNullValues().toString();*/ + return ipAddress.toString() + "/" + subnetAddress.prefixLength(); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/PortAddresses.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/PortAddresses.java new file mode 100644 index 00000000..74f22ae9 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/PortAddresses.java @@ -0,0 +1,127 @@ +/* + * Copyright 2014-2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.host; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; +import org.onosproject.net.ConnectPoint; + +import com.google.common.base.MoreObjects; + +/** + * Represents address information bound to a port. + */ +public final class PortAddresses { + + private final ConnectPoint connectPoint; + private final Set<InterfaceIpAddress> ipAddresses; + private final MacAddress macAddress; + private final VlanId vlan; + + /** + * Constructs a PortAddresses object for the given connection point, with a + * set of IP addresses and a MAC address. Both address parameters are + * optional and can be set to null. + * + * @param connectPoint the connection point these addresses are for + * @param ipAddresses a set of interface IP addresses + * @param mac a MAC address + * @param vlan a VLAN ID + */ + public PortAddresses(ConnectPoint connectPoint, + Set<InterfaceIpAddress> ipAddresses, MacAddress mac, VlanId vlan) { + this.connectPoint = connectPoint; + this.ipAddresses = (ipAddresses == null) ? + Collections.<InterfaceIpAddress>emptySet() + : new HashSet<>(ipAddresses); + this.macAddress = mac; + this.vlan = vlan; + } + + /** + * Returns the connection point this address information is bound to. + * + * @return the connection point + */ + public ConnectPoint connectPoint() { + return connectPoint; + } + + /** + * Returns the set of interface IP addresses. + * + * @return the interface IP addresses + */ + public Set<InterfaceIpAddress> ipAddresses() { + return ipAddresses; + } + + /** + * Returns the MAC address. + * + * @return the MAC address + */ + public MacAddress mac() { + return macAddress; + } + + /** + * Returns the VLAN ID. + * + * @return the VLAN ID + */ + public VlanId vlan() { + return vlan; + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + + if (!(other instanceof PortAddresses)) { + return false; + } + + PortAddresses otherPa = (PortAddresses) other; + + return Objects.equals(this.connectPoint, otherPa.connectPoint) + && Objects.equals(this.ipAddresses, otherPa.ipAddresses) + && Objects.equals(this.macAddress, otherPa.macAddress) + && Objects.equals(this.vlan, otherPa.vlan); + } + + @Override + public int hashCode() { + return Objects.hash(connectPoint, ipAddresses, macAddress, vlan); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("connect-point", connectPoint) + .add("ip-addresses", ipAddresses) + .add("mac-address", macAddress) + .add("vlan", vlan) + .toString(); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/package-info.java new file mode 100644 index 00000000..4f2bc7c4 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * End-station host model & related services API definitions. + */ +package org.onosproject.net.host; |