Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 1 | package org.onlab.onos.sdnip; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkNotNull; |
| 4 | |
| 5 | import java.util.Set; |
| 6 | |
| 7 | import org.apache.commons.lang.NotImplementedException; |
| 8 | import org.onlab.onos.net.ConnectPoint; |
| 9 | import org.onlab.onos.net.host.HostService; |
| 10 | import org.onlab.onos.net.host.PortAddresses; |
| 11 | import org.onlab.onos.sdnip.config.Interface; |
| 12 | import org.onlab.packet.IpAddress; |
| 13 | |
| 14 | import com.google.common.collect.Sets; |
| 15 | |
| 16 | |
| 17 | |
| 18 | /** |
| 19 | * Provides IntefaceService using PortAddresses data from the HostService. |
| 20 | */ |
Jonathan Hart | ce37f6d | 2014-10-20 10:25:03 -0700 | [diff] [blame] | 21 | public class HostToInterfaceAdaptor implements InterfaceService { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 22 | |
| 23 | private final HostService hostService; |
| 24 | |
Jonathan Hart | ce37f6d | 2014-10-20 10:25:03 -0700 | [diff] [blame] | 25 | public HostToInterfaceAdaptor(HostService hostService) { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 26 | this.hostService = checkNotNull(hostService); |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public Set<Interface> getInterfaces() { |
| 31 | Set<PortAddresses> addresses = hostService.getAddressBindings(); |
| 32 | Set<Interface> interfaces = Sets.newHashSetWithExpectedSize(addresses.size()); |
| 33 | for (PortAddresses a : addresses) { |
| 34 | interfaces.add(new Interface(a)); |
| 35 | } |
| 36 | return interfaces; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public Interface getInterface(ConnectPoint connectPoint) { |
| 41 | checkNotNull(connectPoint); |
| 42 | |
| 43 | PortAddresses portAddresses = |
| 44 | hostService.getAddressBindingsForPort(connectPoint); |
| 45 | |
| 46 | if (!portAddresses.ips().isEmpty()) { |
| 47 | return new Interface(portAddresses); |
| 48 | } |
| 49 | |
| 50 | return null; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Interface getMatchingInterface(IpAddress ipAddress) { |
| 55 | // TODO implement |
| 56 | throw new NotImplementedException("getMatchingInteface is not yet implemented"); |
| 57 | } |
| 58 | |
| 59 | } |