protected String getVni(Host host) { return host.annotations().value(VXLAN_ID); }
protected String getTenantId(Host host) { return host.annotations().value(TENANT_ID); }
protected boolean isValidHost(Host host) { return !host.ipAddresses().isEmpty() && host.annotations().value(VXLAN_ID) != null && host.annotations().value(NETWORK_ID) != null && host.annotations().value(TENANT_ID) != null && host.annotations().value(PORT_ID) != null; }
protected Optional<Host> getVmByPortId(String portId) { return Tools.stream(hostService.getHosts()) .filter(this::isValidHost) .filter(host -> host.annotations().value(PORT_ID).equals(portId)) .findFirst(); }
@Override public DeviceId getSfToSffMaping(VirtualPortId portId) { checkNotNull(portId, "portId cannot be null"); VirtualPort vmPort = virtualPortService.getPort(portId); Set<Host> hostSet = hostService.getHostsByMac(vmPort.macAddress()); for (Host host : hostSet) { if (host.annotations().value(IFACEID).equals(vmPort.portId().portId())) { return host.location().deviceId(); } } return null; }
/** * Returns a description of the given host. * * @param host the host * @return a description of the host */ public static HostDescription descriptionOf(Host host) { checkNotNull(host, "Must supply a non-null Host"); return new DefaultHostDescription(host.mac(), host.vlan(), host.locations(), host.ipAddresses(), host.configured(), (SparseAnnotations) host.annotations()); } }
@Override public DeviceId getSfToSffMaping(VirtualPortId portId) { checkNotNull(portId, "portId cannot be null"); VirtualPort vmPort = virtualPortService.getPort(portId); Set<Host> hostSet = hostService.getHostsByMac(vmPort.macAddress()); for (Host host : hostSet) { if (host.annotations().value(IFACEID).equals(vmPort.portId().portId())) { return host.location().deviceId(); } } return null; }
@Override public void onHostDetected(Host host) { DeviceId deviceId = host.location().deviceId(); if (!mastershipService.isLocalMaster(deviceId)) { return; } String ifaceId = host.annotations().value(IFACEID); if (ifaceId == null) { log.error("The ifaceId of Host is null"); return; } programSffAndClassifierHost(host, Objective.Operation.ADD); // apply L2 openflow rules applyHostMonitoredL2Rules(host, Objective.Operation.ADD); // apply L3 openflow rules applyHostMonitoredL3Rules(host, Objective.Operation.ADD); }
/** * Checks whether the last Service Function host of a specific tenant in * this device. * * @param host the host on device * @param deviceId the device identifier * @param tenantId the tenant identifier * @return true or false */ private boolean isLastSFHostOfTenant(Host host, DeviceId deviceId, TenantId tenantId) { Set<Host> hostSet = hostService.getConnectedHosts(deviceId); if (hostSet != null) { for (Host h : hostSet) { String ifaceId = h.annotations().value(IFACEID); if (ifaceId != null) { VirtualPortId hPortId = VirtualPortId.portId(ifaceId); if (virtualPortService.getPort(hPortId).tenantId().tenantId() .equals(tenantId.tenantId()) && isServiceFunction(hPortId)) { if (!h.equals(host)) { return false; } } } } } return true; }
/** * Checks whether the last Service Function host of a specific tenant in * this device. * * @param host the host on device * @param deviceId the device identifier * @param tenantId the tenant identifier * @return true or false */ private boolean isLastSFHostOfTenant(Host host, DeviceId deviceId, TenantId tenantId) { Set<Host> hostSet = hostService.getConnectedHosts(deviceId); if (hostSet != null) { for (Host h : hostSet) { String ifaceId = h.annotations().value(IFACEID); if (ifaceId != null) { VirtualPortId hPortId = VirtualPortId.portId(ifaceId); if (virtualPortService.getPort(hPortId).tenantId().tenantId() .equals(tenantId.tenantId()) && isServiceFunction(hPortId)) { if (!h.equals(host)) { return false; } } } } } return true; }
/** * Checks whether the last Classifier host of a specific tenant in this * device. * * @param host the host on device * @param deviceId the device identifier * @param tenantId the tenant identifier * @return true or false */ private boolean isLastClassifierHostOfTenant(Host host, DeviceId deviceId, TenantId tenantId) { Set<Host> hostSet = hostService.getConnectedHosts(deviceId); if (hostSet != null) { for (Host h : hostSet) { String ifaceId = h.annotations().value(IFACEID); if (ifaceId != null) { VirtualPortId hPortId = VirtualPortId.portId(ifaceId); if (virtualPortService.getPort(hPortId).tenantId().tenantId() .equals(tenantId.tenantId()) && !isServiceFunction(hPortId)) { if (!h.equals(host)) { return false; } } } } } return true; }
/** * Checks whether the last Classifier host of a specific tenant in this * device. * * @param host the host on device * @param deviceId the device identifier * @param tenantId the tenant identifier * @return true or false */ private boolean isLastClassifierHostOfTenant(Host host, DeviceId deviceId, TenantId tenantId) { Set<Host> hostSet = hostService.getConnectedHosts(deviceId); if (hostSet != null) { for (Host h : hostSet) { String ifaceId = h.annotations().value(IFACEID); if (ifaceId != null) { VirtualPortId hPortId = VirtualPortId.portId(ifaceId); if (virtualPortService.getPort(hPortId).tenantId().tenantId() .equals(tenantId.tenantId()) && !isServiceFunction(hPortId)) { if (!h.equals(host)) { return false; } } } } } return true; }
@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; }
@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; }
@Override public void onHostVanished(Host host) { DeviceId deviceId = host.location().deviceId(); if (!mastershipService.isLocalMaster(deviceId)) { return; } String ifaceId = host.annotations().value(IFACEID); if (ifaceId == null) { log.error("The ifaceId of Host is null"); return; } programSffAndClassifierHost(host, Objective.Operation.REMOVE); // apply L2 openflow rules applyHostMonitoredL2Rules(host, Objective.Operation.REMOVE); // apply L3 openflow rules applyHostMonitoredL3Rules(host, Objective.Operation.REMOVE); VirtualPortId virtualPortId = VirtualPortId.portId(ifaceId); vPortStore.remove(virtualPortId); }
he = store.createOrUpdateHost(hp.id(), hostId, desc, false); if (he != null && he.subject() != null) { log.debug("Host annotations update - Host Event : {}", he.subject().annotations());
private DeviceId getDeviceIdOfFloatingIP(FloatingIp floatingIp) { VirtualPortId vmPortId = floatingIp.portId(); VirtualPort vmPort = virtualPortService.getPort(vmPortId); if (vmPort == null) { vmPort = VtnData.getPort(vPortStore, vmPortId); } Set<Host> hostSet = hostService.getHostsByMac(vmPort.macAddress()); Host host = null; for (Host h : hostSet) { String ifaceid = h.annotations().value(IFACEID); if (ifaceid != null && ifaceid.equals(vmPortId.portId())) { host = h; break; } } if (host == null) { return null; } else { return host.location().deviceId(); } }
private void programSffAndClassifierHost(Host host, Objective.Operation type) { DeviceId deviceId = host.location().deviceId(); String ifaceId = host.annotations().value(IFACEID); VirtualPortId virtualPortId = VirtualPortId.portId(ifaceId); VirtualPort virtualPort = virtualPortService.getPort(virtualPortId); if (virtualPort == null) { virtualPort = VtnData.getPort(vPortStore, virtualPortId); } TenantId tenantId = virtualPort.tenantId(); if (Objective.Operation.ADD == type) { vtnRscService.addDeviceIdOfOvsMap(virtualPortId, tenantId, deviceId); } else if (Objective.Operation.REMOVE == type) { vtnRscService.removeDeviceIdOfOvsMap(host, tenantId, deviceId); } }
/** * Prints information about a host. * * @param host end-station host */ protected void printHost(Host host) { if (shortOnly) { print(FMT_SHORT, host.id(), host.mac(), host.locations(), host.vlan(), host.ipAddresses()); } else { print(FMT, host.id(), host.mac(), host.locations(), host.vlan(), host.ipAddresses(), annotations(host.annotations()), host.innerVlan(), host.tpid().toString(), host.providerId().scheme(), host.providerId().id(), host.configured()); } } }
Host host = null; for (Host h : hostSet) { String ifaceid = h.annotations().value(IFACEID); if (ifaceid != null && ifaceid.equals(vmPortId.portId())) { host = h;