Usages of

org.onosproject.net.host.HostService.getAddressBindings()
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected HostService hostService; // code omitted ... /** * Finds ports with an address in the subnet of the target address. * * @param target the target address to find a matching port for * @return a set of PortAddresses describing ports in the subnet */ private Set<PortAddresses> findPortsInSubnet(IpAddress target) { Set<PortAddresses> result = new HashSet<>(); for (PortAddresses addresses : hostService.getAddressBindings()) { result.addAll(addresses.ipAddresses().stream().filter(ia -> ia.subnetAddress().contains(target)). map(ia -> addresses).collect(Collectors.toList())); } return result; }
public HostToInterfaceAdaptor(HostService hostService) { // code omitted ... @Override public Set<Interface> getInterfaces() { Set<PortAddresses> addresses = hostService.getAddressBindings(); Set<Interface> interfaces = Sets.newHashSetWithExpectedSize(addresses.size()); for (PortAddresses a : addresses) { interfaces.add(new Interface(a)); } return interfaces; }
@Override protected void execute() { HostService hostService = get(HostService.class); List<PortAddresses> addresses = Lists.newArrayList(hostService.getAddressBindings()); Collections.sort(addresses, Comparators.ADDRESSES_COMPARATOR); for (PortAddresses pa : addresses) { print(FORMAT, pa.connectPoint().deviceId(), pa.connectPoint().port(), printIpAddresses(pa.ipAddresses()), pa.mac()); } }
@Override protected void execute() { HostService hostService = get(HostService.class); List<PortAddresses> addresses = Lists.newArrayList(hostService.getAddressBindings()); Collections.sort(addresses, Comparators.ADDRESSES_COMPARATOR); for (PortAddresses pa : addresses) { print(FORMAT, pa.connectPoint().deviceId(), pa.connectPoint().port(), printIpAddresses(pa.ipAddresses()), pa.mac(), pa.vlan()); } }
public HostToInterfaceAdaptor(HostService hostService) { // code omitted ... public Set<Interface> getInterfaces() { Set<PortAddresses> addresses = hostService.getAddressBindings(); Set<Interface> interfaces = Sets.newHashSetWithExpectedSize(addresses.size()); for (PortAddresses a : addresses) { interfaces.add(new Interface(a)); } return interfaces; }
public HostToInterfaceAdaptor(HostService hostService) { // code omitted ... public Interface getInterface(IpAddress ip) { Set<PortAddresses> portAddresses = hostService.getAddressBindings(); for (PortAddresses portAddress : portAddresses) { for (InterfaceIpAddress portIp : portAddress.ipAddresses()) { if (portIp.ipAddress().equals(ip)) { return new Interface(portAddress); } } } return null; }
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected HostService hostService; // code omitted ... /** * Finds ports with an address in the subnet of the target address. * * @param target the target address to find a matching port for * @return a set of PortAddresses describing ports in the subnet */ private Set<PortAddresses> findPortsInSubnet(Ip4Address target) { Set<PortAddresses> result = new HashSet<PortAddresses>(); for (PortAddresses addresses : hostService.getAddressBindings()) { for (InterfaceIpAddress ia : addresses.ipAddresses()) { if (ia.subnetAddress().contains(target)) { result.add(addresses); } } } return result; }
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected HostService hostService; // code omitted ... /** * Finds ports with an address in the subnet of the target address. * * @param target the target address to find a matching port for * @return a set of PortAddresses describing ports in the subnet */ private Set<PortAddresses> findPortsInSubnet(IpAddress target) { Set<PortAddresses> result = new HashSet<PortAddresses>(); for (PortAddresses addresses : hostService.getAddressBindings()) { for (InterfaceIpAddress ia : addresses.ipAddresses()) { if (ia.subnetAddress().contains(target)) { result.add(addresses); } } } return result; }
private HostService hostService; // code omitted ... @Before public void setUp() throws Exception { hostService = createMock(HostService.class); portAddresses = Sets.newHashSet(); interfaces = Maps.newHashMap(); InterfaceIpAddress ia11 = new InterfaceIpAddress(IpAddress.valueOf("192.168.1.1"), IpPrefix.valueOf("192.168.1.0/24")); createPortAddressesAndInterface(CP1, Sets.newHashSet(ia11), MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE); // Two addresses in the same subnet InterfaceIpAddress ia21 = new InterfaceIpAddress(IpAddress.valueOf("192.168.2.1"), IpPrefix.valueOf("192.168.2.0/24")); InterfaceIpAddress ia22 = new InterfaceIpAddress(IpAddress.valueOf("192.168.2.2"), IpPrefix.valueOf("192.168.2.0/24")); createPortAddressesAndInterface(CP2, Sets.newHashSet(ia21, ia22), MacAddress.valueOf("00:00:00:00:00:02"), VlanId.vlanId((short) 4)); // Two addresses in different subnets InterfaceIpAddress ia31 = new InterfaceIpAddress(IpAddress.valueOf("192.168.3.1"), IpPrefix.valueOf("192.168.3.0/24")); InterfaceIpAddress ia41 = new InterfaceIpAddress(IpAddress.valueOf("192.168.4.1"), IpPrefix.valueOf("192.168.4.0/24")); createPortAddressesAndInterface(CP3, Sets.newHashSet(ia31, ia41), MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE); expect(hostService.getAddressBindings()).andReturn(portAddresses).anyTimes(); replay(hostService); adaptor = new HostToInterfaceAdaptor(hostService); }
private HostService hostService; // code omitted ... private void addAddressBindings() { Set<PortAddresses> addresses = Sets.newHashSet(); for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); Ip4Prefix prefix1 = Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); Ip4Address addr1 = Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1"); InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); PortAddresses pa1 = new PortAddresses(cp, Sets.newHashSet(ia1), MacAddress.valueOf(2 * i - 1)); PortAddresses pa2 = new PortAddresses(cp, Sets.newHashSet(ia2), MacAddress.valueOf(2 * i)); addresses.add(pa1); addresses.add(pa2); expect(hostService.getAddressBindingsForPort(cp)) .andReturn(Sets.newHashSet(pa1, pa2)).anyTimes(); } expect(hostService.getAddressBindings()).andReturn(addresses).anyTimes(); for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), P1); expect(hostService.getAddressBindingsForPort(cp)) .andReturn(Collections.<PortAddresses>emptySet()).anyTimes(); } }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes