Java Code Examples for org.onosproject.net.HostId#hostId()
The following examples show how to use
org.onosproject.net.HostId#hostId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DhcpManager.java From onos with Apache License 2.0 | 6 votes |
/** * Integrates hosts learned through DHCP into topology. * @param context context of the incoming message * @param ipAssigned IP Address assigned to the host by DHCP Manager */ private void discoverHost(PacketContext context, Ip4Address ipAssigned) { if (!allowHostDiscovery) { // host discovery is not allowed, do nothing return; } Ethernet packet = context.inPacket().parsed(); MacAddress mac = packet.getSourceMAC(); VlanId vlanId = VlanId.vlanId(packet.getVlanID()); HostLocation hostLocation = new HostLocation(context.inPacket().receivedFrom(), 0); Set<IpAddress> ips = new HashSet<>(); ips.add(ipAssigned); HostId hostId = HostId.hostId(mac, vlanId); DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, hostLocation, ips); log.info("Discovered host {}", desc); hostProviderService.hostDetected(hostId, desc, false); }
Example 2
Source File: HostResourceTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests fetch of one host by Id. */ @Test public void testSingleHostByIdFetch() { final ProviderId pid = new ProviderId("of", "foo"); final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01"); final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::")); final Host host1 = new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), ips1); hosts.add(host1); expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))) .andReturn(host1) .anyTimes(); replay(mockHostService); WebTarget wt = target(); String response = wt.path("hosts/00:00:11:00:00:01%2F1").request().get(String.class); final JsonObject result = Json.parse(response).asObject(); assertThat(result, matchesHost(host1)); }
Example 3
Source File: HostResourceTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests fetch of one host by mac and vlan. */ @Test public void testSingleHostByMacAndVlanFetch() { final ProviderId pid = new ProviderId("of", "foo"); final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01"); final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::")); final Host host1 = new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), ips1); hosts.add(host1); expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))) .andReturn(host1) .anyTimes(); replay(mockHostService); WebTarget wt = target(); String response = wt.path("hosts/00:00:11:00:00:01/1").request().get(String.class); final JsonObject result = Json.parse(response).asObject(); assertThat(result, matchesHost(host1)); }
Example 4
Source File: AnnotateHostCommand.java From onos with Apache License 2.0 | 6 votes |
@Override protected void doExecute() { NetworkConfigService netcfgService = get(NetworkConfigService.class); HostId hostId = HostId.hostId(uri); if (key == null) { print("[ERROR] Annotation key not specified."); return; } HostAnnotationConfig cfg = netcfgService.getConfig(hostId, HostAnnotationConfig.class); if (cfg == null) { cfg = new HostAnnotationConfig(hostId); } if (removeCfg) { // remove config about entry cfg.annotation(key); } else { // add request config cfg.annotation(key, value); } netcfgService.applyConfig(hostId, HostAnnotationConfig.class, cfg.node()); }
Example 5
Source File: OpenstackSwitchingHostProviderTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests the process port added method for updating case. */ @Test public void testProcessPortAddedForUpdate() { org.onosproject.net.Port addedPort = new DefaultPort(DEV1, P1, true, ANNOTATIONS); DeviceEvent addedEvent = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV1, addedPort); target.portAddedHelper(addedEvent); //org.onosproject.net.Port updatedPort = new DefaultPort(DEV1, P2, true, ANNOTATIONS); //DeviceEvent updatedEvent = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV1, updatedPort); target.portAddedHelper(addedEvent); HostId hostId = HostId.hostId(HOST_MAC); HostDescription hostDesc = new DefaultHostDescription( HOST_MAC, VlanId.NONE, new HostLocation(CP11, System.currentTimeMillis()), ImmutableSet.of(HOST_IP11), ANNOTATIONS ); verifyHostResult(hostId, hostDesc); }
Example 6
Source File: OpenstackSwitchingHostProviderTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests the process port added method for new addition case. */ @Test public void testProcessPortAddedForNewAddition() { org.onosproject.net.Port port = new DefaultPort(DEV2, P1, true, ANNOTATIONS); DeviceEvent event = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV2, port); target.portAddedHelper(event); HostId hostId = HostId.hostId(HOST_MAC2); HostDescription hostDesc = new DefaultHostDescription( HOST_MAC2, VlanId.NONE, new HostLocation(CP21, System.currentTimeMillis()), ImmutableSet.of(HOST_IP11), ANNOTATIONS ); verifyHostResult(hostId, hostDesc); }
Example 7
Source File: SegmentRoutingManager.java From onos with Apache License 2.0 | 5 votes |
/** * Returns locations of given resolved route. * * @param resolvedRoute resolved route * @return locations of nexthop. Might be empty if next hop is not found */ public Set<ConnectPoint> nextHopLocations(ResolvedRoute resolvedRoute) { HostId hostId = HostId.hostId(resolvedRoute.nextHopMac(), resolvedRoute.nextHopVlan()); return Optional.ofNullable(hostService.getHost(hostId)) .map(Host::locations).orElse(Sets.newHashSet()) .stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet()); }
Example 8
Source File: DhcpRelayManagerTest.java From onos with Apache License 2.0 | 5 votes |
@Test public void testDhcp6DualHome() { PacketContext packetContext = new TestDhcp6ReplyPacketContext(DHCP6.MsgType.REPLY.value(), CLIENT_DH_CP, CLIENT_MAC, CLIENT_VLAN, INTERFACE_IP_V6.ipAddress().getIp6Address(), 0, false, CLIENT_VLAN); reset(manager.hostService); expect(manager.hostService.getHostsByIp(CLIENT_LL_IP_V6)).andReturn(ImmutableSet.of(EXISTS_HOST)).anyTimes(); // FIXME: currently DHCPv6 has a bug, we can't get correct vlan of client...... // XXX: The vlan relied from DHCP6 handler might be wrong, do hack here HostId hostId = HostId.hostId(CLIENT_MAC, VlanId.NONE); expect(manager.hostService.getHost(hostId)).andReturn(EXISTS_HOST).anyTimes(); // XXX: sometimes this will work, sometimes not expect(manager.hostService.getHost(CLIENT_HOST_ID)).andReturn(EXISTS_HOST).anyTimes(); Capture<HostDescription> capturedHostDesc = newCapture(); // XXX: also a hack here mockHostProviderService.hostDetected(eq(hostId), capture(capturedHostDesc), eq(false)); expectLastCall().anyTimes(); mockHostProviderService.hostDetected(eq(CLIENT_HOST_ID), capture(capturedHostDesc), eq(false)); expectLastCall().anyTimes(); replay(mockHostProviderService, manager.hostService); packetService.processPacket(packetContext); assertAfter(PKT_PROCESSING_MS, () -> verify(mockHostProviderService)); assertAfter(PKT_PROCESSING_MS, () -> assertTrue(capturedHostDesc.hasCaptured())); HostDescription hostDesc = capturedHostDesc.getValue(); Set<HostLocation> hostLocations = hostDesc.locations(); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(2, hostLocations.size())); assertAfter(PKT_PROCESSING_MS, () -> assertTrue(hostLocations.contains(CLIENT_LOCATION))); assertAfter(PKT_PROCESSING_MS, () -> assertTrue(hostLocations.contains(CLIENT_DH_LOCATION))); }
Example 9
Source File: DhcpRelayManagerTest.java From onos with Apache License 2.0 | 5 votes |
/** * Relay a DHCP packet without option 82. * Should add new host to host store after dhcp ack. */ @Test public void relayDhcpWithoutAgentInfo() { replay(mockHostProviderService); // send request packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT_MAC, CLIENT_VLAN, CLIENT_CP, INTERFACE_IP.ipAddress().getIp4Address(), false)); // won't trigger the host provider service verify(mockHostProviderService); reset(mockHostProviderService); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(0, mockRouteStore.routes.size())); HostId expectHostId = HostId.hostId(CLIENT_MAC, CLIENT_VLAN); Capture<HostDescription> capturedHostDesc = newCapture(); mockHostProviderService.hostDetected(eq(expectHostId), capture(capturedHostDesc), eq(false)); replay(mockHostProviderService); // send ack packetService.processPacket(new TestDhcpAckPacketContext(CLIENT_CP, CLIENT_MAC, CLIENT_VLAN, INTERFACE_IP.ipAddress().getIp4Address(), false)); assertAfter(PKT_PROCESSING_MS, () -> verify(mockHostProviderService)); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(0, mockRouteStore.routes.size())); HostDescription host = capturedHostDesc.getValue(); assertAfter(PKT_PROCESSING_MS, () -> assertFalse(host.configured())); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(CLIENT_CP.deviceId(), host.location().elementId())); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(CLIENT_CP.port(), host.location().port())); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(1, host.ipAddress().size())); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(IP_FOR_CLIENT, host.ipAddress().iterator().next())); }
Example 10
Source File: Dhcp6HandlerImpl.java From onos with Apache License 2.0 | 5 votes |
/** * Find first ipaddress for a given Host info i.e. mac and vlan. * * @param clientMac client mac * @param vlanId packet's vlan * @return next-hop link-local ipaddress for a given host */ private IpAddress getFirstIpByHost(Boolean directConnFlag, MacAddress clientMac, VlanId vlanId) { IpAddress nextHopIp; // pick out the first link-local ip address HostId gwHostId = HostId.hostId(clientMac, vlanId); Host gwHost = hostService.getHost(gwHostId); if (gwHost == null) { log.warn("Can't find gateway host for hostId {}", gwHostId); return null; } if (directConnFlag) { nextHopIp = gwHost.ipAddresses() .stream() .filter(IpAddress::isIp6) .map(IpAddress::getIp6Address) .findFirst() .orElse(null); } else { nextHopIp = gwHost.ipAddresses() .stream() .filter(IpAddress::isIp6) .filter(ip6 -> ip6.isLinkLocal()) .map(IpAddress::getIp6Address) .findFirst() .orElse(null); } return nextHopIp; }
Example 11
Source File: UiEdgeLink.java From onos with Apache License 2.0 | 5 votes |
/** * Creates a UI link. * * @param topology parent topology * @param id canonicalized link identifier */ public UiEdgeLink(UiTopology topology, UiLinkId id) { super(topology, id); hostId = HostId.hostId(id.idA()); deviceId = (DeviceId) id.elementB(); port = id.portB(); }
Example 12
Source File: PceWebTopovMessageHandler.java From onos with Apache License 2.0 | 5 votes |
/** * provides the element id. */ private ElementId elementId(String id) { try { return DeviceId.deviceId(id); } catch (IllegalArgumentException e) { return HostId.hostId(id); } }
Example 13
Source File: OpenstackNetworkingUiMessageHandler.java From onos with Apache License 2.0 | 5 votes |
private void updateForMode(String id) { try { HostId hid = HostId.hostId(id); elementOfNote = hostService.getHost(hid); } catch (Exception e) { try { DeviceId did = DeviceId.deviceId(id); elementOfNote = deviceService.getDevice(did); } catch (Exception e2) { log.debug("Unable to process ID [{}]", id); elementOfNote = null; } } switch (currentMode) { case MOUSE: sendMouseData(); break; default: break; } }
Example 14
Source File: VtnManager.java From onos with Apache License 2.0 | 5 votes |
public void onVirtualPortDeleted(VtnRscEventFeedback l3Feedback) { VirtualPort vPort = l3Feedback.virtualPort(); HostId hostId = HostId.hostId(vPort.macAddress()); BasicHostConfig basicHostConfig = networkConfigService.addConfig(hostId, BasicHostConfig.class); Set<IpAddress> oldIps = hostService.getHost(hostId).ipAddresses(); // Copy to a new set as oldIps is unmodifiable set. Set<IpAddress> newIps = new HashSet<>(); newIps.addAll(oldIps); for (FixedIp fixedIp : vPort.fixedIps()) { newIps.remove(fixedIp.ip()); } basicHostConfig.setIps(newIps).apply(); }
Example 15
Source File: HostResourceTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests administrative removal of a host. */ @Test public void testDelete() { HostId hostId = HostId.hostId("11:22:33:44:55:66/None"); mockHostService.removeHost(hostId); expectLastCall(); replay(mockHostService); WebTarget wt = target(); Response response = wt.path("hosts/11:22:33:44:55:66/None") .request(MediaType.APPLICATION_JSON_TYPE) .delete(); assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT)); }
Example 16
Source File: MaoRoutingManager.java From ONOS_LoadBalance_Routing_Forward with Apache License 2.0 | 4 votes |
@Override public void process(PacketContext context) { if (context.isHandled()) { return; } Ethernet pkt = context.inPacket().parsed(); if (pkt.getEtherType() == Ethernet.TYPE_IPV4) { HostId srcHostId = HostId.hostId(pkt.getSourceMAC()); HostId dstHostId = HostId.hostId(pkt.getDestinationMAC()); Set<Path> paths = getLoadBalancePaths(srcHostId, dstHostId); if (paths.isEmpty()) { log.warn("paths is Empty !!! no Path is available"); context.block(); return; } IPv4 ipPkt = (IPv4) pkt.getPayload(); TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPSrc(IpPrefix.valueOf(ipPkt.getSourceAddress(), 32)) .matchIPDst(IpPrefix.valueOf(ipPkt.getDestinationAddress(), 32)) .build(); boolean isContain; // synchronized (intentMap) { isContain = intentMap.containsKey(selector.criteria()); // } if (isContain) { context.block(); return; } Path result = paths.iterator().next(); log.info("\n------ Mao Path Info ------\nSrc:{}, Dst:{}\n{}", IpPrefix.valueOf(ipPkt.getSourceAddress(), 32).toString(), IpPrefix.valueOf(ipPkt.getDestinationAddress(), 32), result.links().toString().replace("Default", "\n")); PathIntent pathIntent = PathIntent.builder() .path(result) .appId(appId) .priority(65432) .selector(selector) .treatment(DefaultTrafficTreatment.emptyTreatment()) .build(); intentService.submit(pathIntent); // synchronized (intentMap) { intentMap.put(selector.criteria(), pathIntent); // } context.block(); } }
Example 17
Source File: Dhcp4HandlerImpl.java From onos with Apache License 2.0 | 4 votes |
private void handleLeaseQueryUnknown(Ethernet packet, DHCP dhcpPayload) { log.debug("Lease Query for Client results in DHCPLEASEUNASSIGNED or " + "DHCPLEASEUNKNOWN - removing route & forwarding reply to originator"); if (learnRouteFromLeasequery) { MacAddress clientMacAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress()); VlanId vlanId = VlanId.vlanId(packet.getVlanID()); HostId hostId = HostId.hostId(clientMacAddress, vlanId); DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null); if (record == null) { log.warn("Can't find record for host {} when handling LQ UNKNOWN/UNASSIGNED message", hostId); return; } Ip4Address clientIP = record.ip4Address().orElse(null); log.debug("LQ: IP of host is " + clientIP.getIp4Address()); // find the new NH by looking at the src MAC of the dhcp request // from the LQ store MacAddress nextHopMac = record.nextHop().orElse(null); log.debug("LQ: MAC of resulting *Existing* NH for that route is " + nextHopMac.toString()); // find the next hop IP from its mac HostId gwHostId = HostId.hostId(nextHopMac, vlanId); Host gwHost = hostService.getHost(gwHostId); if (gwHost == null) { log.warn("Can't find gateway for new NH host " + gwHostId); return; } Ip4Address nextHopIp = gwHost.ipAddresses() .stream() .filter(IpAddress::isIp4) .map(IpAddress::getIp4Address) .findFirst() .orElse(null); if (nextHopIp == null) { log.warn("Can't find IP address of gateway {}", gwHost); return; } log.debug("LQ: *Existing* NH IP for host is " + nextHopIp.getIp4Address() + " removing route for it"); Route route = new Route(Route.Source.DHCP, clientIP.toIpPrefix(), nextHopIp); routeStore.removeRoute(route); // remove from temp store dhcpRelayStore.removeDhcpRecord(hostId); } // and forward to client InternalPacket ethernetPacket = processLeaseQueryFromServer(packet); if (ethernetPacket != null) { sendResponseToClient(ethernetPacket, dhcpPayload); } }
Example 18
Source File: DefaultCheckLoopTest.java From onos with Apache License 2.0 | 4 votes |
private Host produceOneHost(DeviceId dpid, int port) { return new DefaultHost(NONE, HostId.hostId(HOSTID_EXAMPLE), MacAddress.valueOf(0), VlanId.vlanId(), new HostLocation(dpid, portNumber(port), 1), ImmutableSet.of(), EMPTY); }
Example 19
Source File: SubjectFactories.java From onos with Apache License 2.0 | 4 votes |
@Override public HostId createSubject(String key) { return HostId.hostId(key); }
Example 20
Source File: PathsWebResource.java From onos with Apache License 2.0 | 2 votes |
/** * Determines if the id appears to be the id of a host. * Host id format is 00:00:00:00:00:01/-1 * * @param id id string * @return HostId if the id is valid, null otherwise */ private HostId isHostId(String id) { return id.matches("..:..:..:..:..:../.*") ? HostId.hostId(id) : null; }