@Override public boolean equals(Object obj) { if (this == obj) { return true; } if ((obj == null) || (!(obj instanceof IpPrefix))) { return false; } IpPrefix other = (IpPrefix) obj; return ((prefixLength == other.prefixLength) && address.equals(other.address)); }
@Override public boolean equals(Object obj) { return address.equals(obj); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof PIMAddrSource)) { return false; } final PIMAddrSource other = (PIMAddrSource) obj; if (this.family != other.family) { return false; } if (this.encType != other.encType) { return false; } if (!this.addr.equals(other.addr)) { return false; } return true; } }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof PIMAddrGroup)) { return false; } final PIMAddrGroup other = (PIMAddrGroup) obj; if (this.family != other.family) { return false; } if (this.encType != other.encType) { return false; } if (!this.addr.equals(other.addr)) { return false; } return true; } }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof PIMAddrUnicast)) { return false; } final PIMAddrUnicast other = (PIMAddrUnicast) obj; if (this.family != other.family) { return false; } if (this.encType != other.encType) { return false; } if (!this.addr.equals(other.addr)) { return false; } return true; } }
/** * Examines if BGP peer is connected. * * @param peer IP address of peer * @return result of search */ public boolean isConnectedToPeer(IpAddress peer) { for (final IpAddress entry : peers()) { if (entry.equals(peer)) { return true; } } return false; }
@Override public Set<Interface> getInterfacesByIp(IpAddress ip) { return interfaces.values() .stream() .flatMap(Collection::stream) .filter(intf -> intf.ipAddressesList() .stream() .anyMatch(ia -> ia.ipAddress().equals(ip))) .collect(collectingAndThen(toSet(), ImmutableSet::copyOf)); }
@Override public RestSBDevice getDevice(IpAddress ip, int port) { return deviceMap.values().stream().filter(v -> v.ip().equals(ip) && v.port() == port).findFirst().get(); }
/** * Returns true if the interface has the given IP address. * * @param intf interface to check * @param ip IP address * @return true if the IP is configured on the interface, otherwise false */ private boolean hasIp(Interface intf, IpAddress ip) { return intf.ipAddressesList().stream() .anyMatch(intfAddress -> intfAddress.ipAddress().equals(ip)); }
@Override public VirtualPort getPort(TenantNetworkId networkId, IpAddress ip) { checkNotNull(networkId, NETWORKID_NOT_NULL); checkNotNull(ip, IP_NOT_NULL); List<VirtualPort> vPorts = new ArrayList<>(); vPortStore.values().stream().filter(p -> p.networkId().equals(networkId)) .forEach(p -> { Iterator<FixedIp> fixedIps = p.fixedIps().iterator(); while (fixedIps.hasNext()) { if (fixedIps.next().ip().equals(ip)) { vPorts.add(p); break; } } }); if (vPorts.size() == 0) { return null; } return vPorts.get(0); }
@Override public VirtualPort getPort(TenantNetworkId networkId, IpAddress ip) { checkNotNull(networkId, NETWORKID_NOT_NULL); checkNotNull(ip, IP_NOT_NULL); List<VirtualPort> vPorts = new ArrayList<>(); vPortStore.values().stream().filter(p -> p.networkId().equals(networkId)) .forEach(p -> { Iterator<FixedIp> fixedIps = p.fixedIps().iterator(); while (fixedIps.hasNext()) { if (fixedIps.next().ip().equals(ip)) { vPorts.add(p); break; } } }); if (vPorts.size() == 0) { return null; } return vPorts.get(0); }
@Override public boolean floatingIpIsUsed(IpAddress floatingIpAddr, FloatingIpId floatingIpId) { checkNotNull(floatingIpAddr, "Floating IP address cannot be null"); checkNotNull(floatingIpId, "Floating IP Id cannot be null"); Collection<FloatingIp> floatingIps = getFloatingIps(); for (FloatingIp floatingIp : floatingIps) { if (floatingIp.floatingIp().equals(floatingIpAddr) && !floatingIp.id().equals(floatingIpId)) { return true; } } return false; }
@Override public boolean floatingIpIsUsed(IpAddress floatingIpAddr, FloatingIpId floatingIpId) { checkNotNull(floatingIpAddr, "Floating IP address cannot be null"); checkNotNull(floatingIpId, "Floating IP Id cannot be null"); Collection<FloatingIp> floatingIps = getFloatingIps(); for (FloatingIp floatingIp : floatingIps) { if (floatingIp.floatingIp().equals(floatingIpAddr) && !floatingIp.id().equals(floatingIpId)) { return true; } } return false; }
@Override public boolean equals(Object toBeCompared) { if (toBeCompared instanceof NetconfDeviceInfo) { NetconfDeviceInfo netconfDeviceInfo = (NetconfDeviceInfo) toBeCompared; if (netconfDeviceInfo.name().equals(name) && netconfDeviceInfo.ip().equals(ipAddress) && netconfDeviceInfo.port() == port && netconfDeviceInfo.password().equals(password)) { return true; } } return false; } }
/** * Determines whether a given IP address is contained within this prefix. * * @param other the IP address to test * @return true if the IP address is contained in this prefix, otherwise * false */ public boolean contains(IpAddress other) { if (version() != other.version()) { return false; } // // Mask the other address with my prefix length. // If the other prefix is within this prefix, the masked address must // be same as the address of this prefix. // IpAddress maskedAddr = IpAddress.makeMaskedAddress(other, this.prefixLength); return this.address.equals(maskedAddr); }
@Override public boolean fixedIpIsUsed(IpAddress fixedIpAddr, TenantId tenantId, FloatingIpId floatingIpId) { checkNotNull(fixedIpAddr, "Fixed IP address cannot be null"); checkNotNull(tenantId, "Tenant Id cannot be null"); checkNotNull(floatingIpId, "Floating IP Id cannot be null"); Collection<FloatingIp> floatingIps = getFloatingIps(); for (FloatingIp floatingIp : floatingIps) { IpAddress fixedIp = floatingIp.fixedIp(); if (fixedIp != null) { if (fixedIp.equals(fixedIpAddr) && floatingIp.tenantId().equals(tenantId) && !floatingIp.id().equals(floatingIpId)) { return true; } } } return false; }
/** * Check for given ip match with the fixed ips for the virtual port. * * @param vPortId virtual port id * @param ip ip address to match * @return true if the ip match with the fixed ips in virtual port false otherwise */ private boolean checkIpInVirtualPort(VirtualPortId vPortId, IpAddress ip) { boolean found = false; Set<FixedIp> ips = virtualPortService.getPort(vPortId).fixedIps(); for (FixedIp fixedIp : ips) { if (fixedIp.ip().equals(ip)) { found = true; break; } } return found; }
@Override public boolean fixedIpIsUsed(IpAddress fixedIpAddr, TenantId tenantId, FloatingIpId floatingIpId) { checkNotNull(fixedIpAddr, "Fixed IP address cannot be null"); checkNotNull(tenantId, "Tenant Id cannot be null"); checkNotNull(floatingIpId, "Floating IP Id cannot be null"); Collection<FloatingIp> floatingIps = getFloatingIps(); for (FloatingIp floatingIp : floatingIps) { IpAddress fixedIp = floatingIp.fixedIp(); if (fixedIp != null) { if (fixedIp.equals(fixedIpAddr) && floatingIp.tenantId().equals(tenantId) && !floatingIp.id().equals(floatingIpId)) { return true; } } } return false; }
/** * Determines whether a given IP prefix is contained within this prefix. * * @param other the IP prefix to test * @return true if the other IP prefix is contained in this prefix, * otherwise false */ public boolean contains(IpPrefix other) { if (version() != other.version()) { return false; } if (this.prefixLength > other.prefixLength) { return false; // This prefix has smaller prefix size } // // Mask the other address with my prefix length. // If the other prefix is within this prefix, the masked address must // be same as the address of this prefix. // IpAddress maskedAddr = IpAddress.makeMaskedAddress(other.address, this.prefixLength); return this.address.equals(maskedAddr); }
@Override public MacAddress getGatewayMac(HostId hostId) { checkNotNull(hostId, "hostId cannot be null"); Host host = hostService.getHost(hostId); String ifaceId = host.annotations().value(IFACEID); VirtualPortId hPortId = VirtualPortId.portId(ifaceId); VirtualPort hPort = virtualPortService.getPort(hPortId); SubnetId subnetId = hPort.fixedIps().iterator().next().subnetId(); Subnet subnet = subnetService.getSubnet(subnetId); IpAddress gatewayIp = subnet.gatewayIp(); Iterable<VirtualPort> virtualPorts = virtualPortService.getPorts(); MacAddress macAddress = null; for (VirtualPort port : virtualPorts) { Set<FixedIp> fixedIpSet = port.fixedIps(); for (FixedIp fixedIp : fixedIpSet) { if (fixedIp.ip().equals(gatewayIp)) { macAddress = port.macAddress(); } } } return macAddress; }