当前位置: 首页>>代码示例>>Java>>正文


Java IpAddress类代码示例

本文整理汇总了Java中org.onlab.packet.IpAddress的典型用法代码示例。如果您正苦于以下问题:Java IpAddress类的具体用法?Java IpAddress怎么用?Java IpAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IpAddress类属于org.onlab.packet包,在下文中一共展示了IpAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@Override
public ObjectNode encode(Host host, CodecContext context) {
    checkNotNull(host, "Host cannot be null");
    final JsonCodec<HostLocation> locationCodec =
            context.codec(HostLocation.class);
    final ObjectNode result = context.mapper().createObjectNode()
            .put("id", host.id().toString())
            .put("mac", host.mac().toString())
            .put("vlan", host.vlan().toString());

    final ArrayNode jsonIpAddresses = result.putArray("ipAddresses");
    for (final IpAddress ipAddress : host.ipAddresses()) {
        jsonIpAddresses.add(ipAddress.toString());
    }
    result.set("ipAddresses", jsonIpAddresses);
    result.set("location", locationCodec.encode(host.location(), context));

    return annotate(result, host, context);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:HostCodec.java

示例2: updateNextHop

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@Override
public void updateNextHop(IpAddress ip, MacAddress mac) {
    Collection<Route> routes = getDefaultRouteTable(ip).getRoutesForNextHop(ip);

    if (!routes.isEmpty() && !mac.equals(nextHops.get(ip))) {
        MacAddress oldMac = nextHops.put(ip, mac);

        for (Route route : routes) {
            if (oldMac == null) {
                notifyDelegate(new RouteEvent(RouteEvent.Type.ROUTE_ADDED,
                        new ResolvedRoute(route, mac)));
            } else {
                notifyDelegate(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED,
                        new ResolvedRoute(route, mac)));
            }
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:LocalRouteStore.java

示例3: read

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@Override
public IpPrefix read(Kryo kryo, Input input,
        Class<IpPrefix> type) {
    int octLen = input.readInt();
    checkArgument(octLen <= IpAddress.INET6_BYTE_LENGTH);
    byte[] octs = new byte[octLen];
    input.readBytes(octs);
    int prefLen = input.readInt();
    // Use the address size to decide whether it is IPv4 or IPv6 address
    if (octLen == IpAddress.INET_BYTE_LENGTH) {
        return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen);
    }
    if (octLen == IpAddress.INET6_BYTE_LENGTH) {
        return IpPrefix.valueOf(IpAddress.Version.INET6, octs, prefLen);
    }
    return null;    // Shouldn't be reached
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:IpPrefixSerializer.java

示例4: getMacFromHostService

import org.onlab.packet.IpAddress; //导入依赖的package包/类
/**
 * Returns MAC address of a host with a given target IP address by asking to
 * host service. It does not support overlapping IP.
 *
 * @param targetIp target ip
 * @return mac address, or null if it fails to find the mac
 */
private MacAddress getMacFromHostService(IpAddress targetIp) {
    checkNotNull(targetIp);

    Host host = hostService.getHostsByIp(targetIp)
            .stream()
            .findFirst()
            .orElse(null);

    if (host != null) {
        log.debug("Found MAC from host service for {}", targetIp.toString());
        return host.mac();
    } else {
        return null;
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:OpenstackArpHandler.java

示例5: getGwIpAndMac

import org.onlab.packet.IpAddress; //导入依赖的package包/类
private List getGwIpAndMac(VirtualPort port) {
    List list = new ArrayList();
    MacAddress gwMac = null;
    SubnetId subnetId = null;
    IpAddress gwIp = null;
    Iterator<FixedIp> fixips = port.fixedIps().iterator();
    if (fixips.hasNext()) {
        FixedIp fixip = fixips.next();
        subnetId = fixip.subnetId();
        gwIp = subnetService.getSubnet(subnetId).gatewayIp();
        FixedIp fixedGwIp = FixedIp.fixedIp(fixip.subnetId(), gwIp);
        VirtualPort gwPort = virtualPortService.getPort(fixedGwIp);
        if (gwPort == null) {
            gwPort = VtnData.getPort(vPortStore, fixedGwIp);
        }
        gwMac = gwPort.macAddress();
    }
    list.add(gwIp);
    list.add(gwMac);
    return list;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:VtnManager.java

示例6: getGatewayMac

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:VtnRscManager.java

示例7: fwdObjBuilder

import org.onlab.packet.IpAddress; //导入依赖的package包/类
/**
 * Creates a forwarding objective builder for multicast.
 *
 * @param mcastIp multicast group
 * @param assignedVlan assigned VLAN ID
 * @param nextId next ID of the L3 multicast group
 * @return forwarding objective builder
 */
private ForwardingObjective.Builder fwdObjBuilder(IpAddress mcastIp,
        VlanId assignedVlan, int nextId) {
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    IpPrefix mcastPrefix = IpPrefix.valueOf(mcastIp, IpPrefix.MAX_INET_MASK_LENGTH);
    sbuilder.matchEthType(Ethernet.TYPE_IPV4);
    sbuilder.matchIPDst(mcastPrefix);
    TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
    metabuilder.matchVlanId(assignedVlan);

    ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder();
    fwdBuilder.withSelector(sbuilder.build())
            .withMeta(metabuilder.build())
            .nextStep(nextId)
            .withFlag(ForwardingObjective.Flag.SPECIFIC)
            .fromApp(srManager.appId)
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    return fwdBuilder;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:McastHandler.java

示例8: execute

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@Override
protected void execute() {
    SubnetService service = get(SubnetService.class);
    if (id == null || networkId == null || tenantId == null) {
        print("id,networkId,tenantId can not be null");
        return;
    }
    Subnet subnet = new DefaultSubnet(SubnetId.subnetId(id), subnetName,
                                      TenantNetworkId.networkId(networkId),
                                      TenantId.tenantId(tenantId), ipVersion,
                                      cidr == null ? null : IpPrefix.valueOf(cidr),
                                      gatewayIp == null ? null : IpAddress.valueOf(gatewayIp),
                                      dhcpEnabled, shared, hostRoutes,
                                      ipV6AddressMode == null ? null : Mode.valueOf(ipV6AddressMode),
                                      ipV6RaMode == null ? null : Mode.valueOf(ipV6RaMode),
                                      allocationPools);
    Set<Subnet> subnetsSet = Sets.newHashSet();
    subnetsSet.add(subnet);
    service.updateSubnets(subnetsSet);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:SubnetUpdateCommand.java

示例9: testAddDevice

import org.onlab.packet.IpAddress; //导入依赖的package包/类
/**
 * Tests adding new Device to a openflow router.
 */
@Test
public void testAddDevice() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet();
    interfaceIpAddresses4
            .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));

    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses4,
            MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    interfaces.add(sw1Eth4);
    EasyMock.reset(flowObjectiveService);
    setUpFlowObjectiveService();
    deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, dev3));
    verify(flowObjectiveService);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:ControlPlaneRedirectManagerTest.java

示例10: discoverHost

import org.onlab.packet.IpAddress; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:DhcpManager.java

示例11: getPort

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@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);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:VirtualPortManager.java

示例12: processPacketIn

import org.onlab.packet.IpAddress; //导入依赖的package包/类
private void processPacketIn(InboundPacket pkt) {

        boolean ipMatches = false;
        Ethernet ethernet = pkt.parsed();
        IPv4 ipv4 = (IPv4) ethernet.getPayload();
        ConnectPoint connectPoint = pkt.receivedFrom();
        IpAddress destIpAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
        Interface targetInterface = interfaceService.getMatchingInterface(destIpAddress);

        if (targetInterface == null) {
            log.trace("No matching interface for {}", destIpAddress);
            return;
        }

        for (InterfaceIpAddress interfaceIpAddress: targetInterface.ipAddresses()) {
            if (interfaceIpAddress.ipAddress().equals(destIpAddress)) {
                ipMatches = true;
                break;
            }
        }

        if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST &&
                ipMatches) {
            sendIcmpResponse(ethernet, connectPoint);
        }
    }
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:IcmpHandler.java

示例13: arpresponceProcess

import org.onlab.packet.IpAddress; //导入依赖的package包/类
private void arpresponceProcess(ARP arpPacket, DeviceId deviceId) {
    MacAddress srcMac = MacAddress
            .valueOf(arpPacket.getTargetHardwareAddress());
    MacAddress dstMac = MacAddress
            .valueOf(arpPacket.getSenderHardwareAddress());
    IpAddress srcIp = IpAddress.valueOf(IPv4
            .toIPv4Address(arpPacket.getTargetProtocolAddress()));
    IpAddress dstIp = IpAddress.valueOf(IPv4
            .toIPv4Address(arpPacket.getSenderProtocolAddress()));
    FloatingIp floatingIp = floatingIpStore.get(srcIp);
    if (floatingIp == null) {
        return;
    }
    DeviceId deviceIdOfFloatingIp = getDeviceIdOfFloatingIP(floatingIp);
    if (!deviceId.equals(deviceIdOfFloatingIp)) {
        return;
    }
    if (!downloadSnatRules(deviceId, srcMac, srcIp, dstMac, dstIp,
                           floatingIp)) {
        return;
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:VtnManager.java

示例14: testTunnelRemoved

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@Test
public void testTunnelRemoved() {
    TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress
            .valueOf("192.168.1.1"));
    TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
            .valueOf("192.168.1.3"));
    SparseAnnotations annotations = DefaultAnnotations.builder()
            .set("bandwidth", "1024").build();

    List<Link> links = new ArrayList<Link>();
    links.add(link);
    TunnelDescription tunnel = new DefaultTunnelDescription(
                                                            TunnelId.valueOf("1234"),
                                                            src,
                                                            dst,
                                                            Tunnel.Type.VXLAN,
                                                            new DefaultGroupId(0),
                                                            this.provider.id(),
                                                            TunnelName.tunnelName("tunnel1"),
                                                            new DefaultPath(this.provider.id(), links, 0.3),
                                                            annotations);
    provider.tunnelRemoved(tunnel);
    assertEquals(0, providerService.tunnelSet.size());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:25,代码来源:OvsdbTunnelProviderTest.java

示例15: deleteVbng

import org.onlab.packet.IpAddress; //导入依赖的package包/类
@Override
public IpAddress deleteVbng(IpAddress privateIpAddress) {
    // Recycle the public IP address assigned to this private IP address.
    // Recycling will also delete the mapping entry from the private IP
    // address to public IP address.
    IpAddress assignedPublicIpAddress = vbngConfigurationService
            .recycleAssignedPublicIpAddress(privateIpAddress);
    if (assignedPublicIpAddress == null) {
        return null;
    }

    // Remove the private IP address from privateIpAddressMap
    privateIpAddressMap.remove(privateIpAddress);

    // Remove intents
    removeForwardingPaths(privateIpAddress);

    return assignedPublicIpAddress;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:VbngManager.java


注:本文中的org.onlab.packet.IpAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。