@Override public HostEvent removeHost(HostId hostId) { synchronized (this) { Host host = hosts.remove(hostId); if (host != null) { locations.remove((host.location()), host); return new HostEvent(HOST_REMOVED, host); } return null; } }
private void peerRemoved(HostEvent event) { Host peer = event.subject(); Optional<Interface> peerIntf = interfaceService.getInterfacesByPort(peer.location()).stream() .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) .filter(intf -> peer.vlan().equals(intf.vlan())) if (!peerIntf.isPresent()) { log.debug("Removing peer {}/{} on {} but the interface is not configured", peer.mac(), peer.vlan(), peer.location()); return; flowObjectiveService.forward(peer.location().deviceId(), createPeerObjBuilder(toRouterL3Unicast, routerIp.ipAddress().toIpPrefix()).remove()); }); flowObjectiveService.forward(peer.location().deviceId(), createPeerObjBuilder(toPeerL3Unicast, peerIp.toIpPrefix()).remove()); });
private void sendEastWestL3Flows(Host h, MacAddress srcVmGwMac, SegmentationId l3vni, IpAddress srcGwIp, TenantNetwork network, IpAddress dstVmIP, MacAddress dstVmGwMac, Objective.Operation operation) { classifierService .programL3InPortClassifierRules(h.location().deviceId(), h.location().port(), h.mac(), srcVmGwMac, l3vni, operation); classifierService .programArpClassifierRules(h.location().deviceId(), h.location().port(), srcGwIp, network.segmentationId(), operation); Iterable<Device> devices = deviceService.getAvailableDevices(); Sets.newHashSet(devices).stream() .filter(d -> Device.Type.SWITCH == d.type()).forEach(d -> { // L3FWD rules l3ForwardService.programRouteRules(d.id(), l3vni, dstVmIP, network.segmentationId(), dstVmGwMac, h.mac(), operation); }); }
@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 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; }
private void peerAdded(HostEvent event) { Host peer = event.subject(); Optional<Interface> peerIntf = interfaceService.getInterfacesByPort(peer.location()).stream() .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) .filter(intf -> peer.vlan().equals(intf.vlan())) .findFirst(); if (!peerIntf.isPresent()) { log.debug("Adding peer {}/{} on {} but the interface is not configured", peer.mac(), peer.vlan(), peer.location()); return; } // Generate L3 Unicast groups and store it in the map int toRouterL3Unicast = createPeerGroup(peer.mac(), peerIntf.get().mac(), peer.vlan(), peer.location().deviceId(), controlPlaneConnectPoint.port()); int toPeerL3Unicast = createPeerGroup(peerIntf.get().mac(), peer.mac(), peer.vlan(), peer.location().deviceId(), peer.location().port()); peerNextId.put(peer, ImmutableSortedSet.of(toRouterL3Unicast, toPeerL3Unicast)); // From peer to router peerIntf.get().ipAddresses().forEach(routerIp -> { flowObjectiveService.forward(peer.location().deviceId(), createPeerObjBuilder(toRouterL3Unicast, routerIp.ipAddress().toIpPrefix()).add()); }); // From router to peer peer.ipAddresses().forEach(peerIp -> { flowObjectiveService.forward(peer.location().deviceId(), createPeerObjBuilder(toPeerL3Unicast, peerIp.toIpPrefix()).add()); }); }
@Override public void event(HostEvent event) { Host host = event.subject(); if (!mastershipService.isLocalMaster(host.location().deviceId())) { // do not allow to proceed without mastership return; } if (!isValidHost(host)) { log.debug("Invalid host event, ignore it {}", host); return; } switch (event.type()) { case HOST_UPDATED: case HOST_ADDED: eventExecutor.execute(() -> hostDetected(host)); break; case HOST_REMOVED: eventExecutor.execute(() -> hostRemoved(host)); break; default: break; } } }
@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); }
private void sendNorthSouthL3Flows(DeviceId deviceId, FloatingIp floatingIp, IpAddress dstVmGwIp, MacAddress dstVmGwMac, SegmentationId l3vni, TenantNetwork vmNetwork, VirtualPort vmPort, Host host, Objective.Operation operation) { l3ForwardService .programRouteRules(deviceId, l3vni, floatingIp.fixedIp(), vmNetwork.segmentationId(), dstVmGwMac, vmPort.macAddress(), operation); classifierService.programL3InPortClassifierRules(deviceId, host.location().port(), host.mac(), dstVmGwMac, l3vni, operation); classifierService.programArpClassifierRules(deviceId, host.location() .port(), dstVmGwIp, vmNetwork.segmentationId(), operation); }
@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); }
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(); } }
@Override public void event(HostEvent event) { DeviceId deviceId = event.subject().location().deviceId(); if (!mastershipService.isLocalMaster(deviceId)) { return; } switch (event.type()) { case HOST_ADDED: peerAdded(event); break; case HOST_MOVED: //TODO We assume BGP peer does not move for now break; case HOST_REMOVED: peerRemoved(event); break; case HOST_UPDATED: //TODO We assume BGP peer does not change IP for now break; default: break; } } }
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); } }
.getNetwork(virtualPort.networkId()); SegmentationId segmentationId = network.segmentationId(); DeviceId remoteDeviceId = host.location().deviceId(); Device remoteDevice = deviceService.getDevice(remoteDeviceId); String remoteControllerIp = VtnData
MacAddress srcMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())).macAddress(); Host host = hostService.getHost(HostId.hostId(srcMacAddress)); PortNumber port = host.location().port();
MacAddress srcMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.egress())).macAddress(); Host host = hostService.getHost(HostId.hostId(srcMacAddress)); PortNumber port = host.location().port();
MacAddress srcMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.egress())).macAddress(); Host host = hostService.getHost(HostId.hostId(srcMacAddress)); PortNumber port = host.location().port();
DeviceId deviceId = host.location().deviceId(); Port exPort = exPortOfDevice.get(deviceId); TenantRouter tenantRouter = TenantRouter