Java Code Examples for org.onlab.packet.IpPrefix#valueOf()

The following examples show how to use org.onlab.packet.IpPrefix#valueOf() . 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: SegmentRoutingAppConfig.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets ips to blackhole from the config.
 *
 * @return Set of ips to blackhole, empty is not specified,
 * or null if not valid
 */
public Set<IpPrefix> blackholeIPs() {
    if (!object.has(BLACKHOLE_IPS)) {
        return ImmutableSet.of();
    }

    ImmutableSet.Builder<IpPrefix> builder = ImmutableSet.builder();
    ArrayNode arrayNode = (ArrayNode) object.path(BLACKHOLE_IPS);
    for (JsonNode jsonNode : arrayNode) {
        IpPrefix address;

        String addrStr = jsonNode.asText(null);
        if (addrStr != null) {
            try {
                address = IpPrefix.valueOf(addrStr);
                builder.add(address);
            } catch (IllegalArgumentException e) {
                log.debug("Not adding {}", jsonNode, e);
            }
        }
    }
    return builder.build();
}
 
Example 2
Source File: MappingAddressBuilder.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Converts AFI address to generalized mapping address.
 *
 * @param afiAddress IP typed AFI address
 * @return generalized mapping address
 */
private static MappingAddress afi2mapping(LispAfiAddress afiAddress) {
    switch (afiAddress.getAfi()) {
        case IP4:
            IpAddress ipv4Address = ((LispIpv4Address) afiAddress).getAddress();
            IpPrefix ipv4Prefix = IpPrefix.valueOf(ipv4Address, IPV4_PREFIX_LENGTH);
            return MappingAddresses.ipv4MappingAddress(ipv4Prefix);
        case IP6:
            IpAddress ipv6Address = ((LispIpv6Address) afiAddress).getAddress();
            IpPrefix ipv6Prefix = IpPrefix.valueOf(ipv6Address, IPV6_PREFIX_LENGTH);
            return MappingAddresses.ipv6MappingAddress(ipv6Prefix);
        default:
            log.warn("Only support to convert IP address type");
            break;
    }
    return null;
}
 
Example 3
Source File: LispExtensionMappingAddressInterpreter.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Converts AFI address to generalized mapping address.
 *
 * @param afi IP typed AFI address
 * @return generalized mapping address
 */
private MappingAddress afi2mapping(LispAfiAddress afi) {
    switch (afi.getAfi()) {
        case IP4:
            IpAddress ipv4Address = ((LispIpv4Address) afi).getAddress();
            IpPrefix ipv4Prefix = IpPrefix.valueOf(ipv4Address, IPV4_PREFIX_LENGTH);
            return MappingAddresses.ipv4MappingAddress(ipv4Prefix);
        case IP6:
            IpAddress ipv6Address = ((LispIpv6Address) afi).getAddress();
            IpPrefix ipv6Prefix = IpPrefix.valueOf(ipv6Address, IPV6_PREFIX_LENGTH);
            return MappingAddresses.ipv6MappingAddress(ipv6Prefix);
        default:
            log.warn("Only support to convert IP address type");
            break;
    }
    return null;
}
 
Example 4
Source File: RouteCodec.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Route decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }

    IpPrefix prefix = IpPrefix.valueOf(json.path(PREFIX).asText());
    IpAddress nextHop = IpAddress.valueOf(json.path(NEXT_HOP).asText());
    String source = json.path(SOURCE).asText();

    // Routes through the REST API without mentioning source in the json are created as STATIC,
    // otherwise routes are created with corresponding source.

    Route route = source.isEmpty() ?
            new Route(Route.Source.STATIC, prefix, nextHop) :
            new Route(Route.Source.valueOf(source), prefix, nextHop);
    return route;
}
 
Example 5
Source File: SfcFlowRuleInstallerImplTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private FlowClassifier createFlowClassifier(FlowClassifierId id) {
    final String name = "FlowClassifier1";
    final String description = "FlowClassifier1";
    final String ethType = "IPv4";
    final String protocol = "tcp";
    final int minSrcPortRange = 5;
    final int maxSrcPortRange = 10;
    final int minDstPortRange = 5;
    final int maxDstPortRange = 10;
    final TenantId tenantId = TenantId.tenantId("1");
    final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
    final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0");
    final VirtualPortId virtualSrcPort = id1;
    final VirtualPortId virtualDstPort = id2;

    DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
    final FlowClassifier flowClassifier = flowClassifierBuilder.setFlowClassifierId(id)
            .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
            .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
            .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
            .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
    return flowClassifier;
}
 
Example 6
Source File: PiCriterionTranslatorsTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testIpCriterion() throws Exception {
    IpPrefix prefix1 = IpPrefix.valueOf(random.nextInt(), random.nextInt(32));
    int bitWidth = prefix1.address().toOctets().length * 8;

    IPCriterion criterion = (IPCriterion) Criteria.matchIPDst(prefix1);

    PiLpmFieldMatch lpmMatch = (PiLpmFieldMatch) translateCriterion(criterion, fieldId, LPM, bitWidth);

    assertThat(lpmMatch.value().asArray(), is(criterion.ip().address().toOctets()));
    assertThat(lpmMatch.prefixLength(), is(criterion.ip().prefixLength()));
}
 
Example 7
Source File: DefaultMappingTreatmentTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests illegal multicast type instruction construction.
 */
@Test(expected = IllegalArgumentException.class)
public void testIllegalMulticastTypeConstruction() {
    IpPrefix ip = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ip);

    DefaultMappingTreatment.builder()
            .withAddress(address)
            .setMulticastPriority(10)
            .setMulticastWeight(10)
            .setMulticastPriority(20)
            .build();
}
 
Example 8
Source File: DefaultMappingTreatmentTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests method defined on the Builder.
 */
@Test
public void testBuilderMethods() {
    IpPrefix ip = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ip);

    MappingTreatment.Builder builder =
            DefaultMappingTreatment.builder()
                    .withAddress(address)
                    .setUnicastPriority(10)
                    .setUnicastWeight(10);
    MappingTreatment treatment = builder.build();
    assertThat(treatment.instructions(), hasSize(2));
}
 
Example 9
Source File: SfcManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the operation of onFlowClassifierDeleted() method.
 */
@Test
public void testOnFlowClassifierDeleted() {
    final String name = "FlowClassifier";
    final String description = "FlowClassifier";
    final String ethType = "IPv4";
    final String protocol = "udp";
    final int minSrcPortRange = 1024;
    final int maxSrcPortRange = 5000;
    final int minDstPortRange = 1024;
    final int maxDstPortRange = 5000;
    final FlowClassifierId flowClassifierId = FlowClassifierId.of("71111111-fc23-aeb6-f44b-56dc5e2fb3ae");
    final TenantId tenantId = TenantId.tenantId("8");
    final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
    final IpPrefix dstIpPrefix = IpPrefix.valueOf("100.100.100.100/0");
    final VirtualPortId virtualSrcPort = VirtualPortId.portId("100");
    final VirtualPortId virtualDstPort = VirtualPortId.portId("200");
    DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
    FlowClassifier flowClassifier = null;
    SfcService sfcService = new SfcManager();

    // create flow classifier
    flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId).setTenantId(tenantId)
            .setName(name).setDescription(description).setEtherType(ethType).setProtocol(protocol)
            .setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
            .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
            .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
    sfcService.onFlowClassifierDeleted(flowClassifier);
}
 
Example 10
Source File: RouteAddCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    RouteAdminService service = AbstractShellCommand.get(RouteAdminService.class);

    IpPrefix prefix = IpPrefix.valueOf(prefixString);
    IpAddress nextHop = IpAddress.valueOf(nextHopString);

    service.update(Collections.singleton(new Route(Route.Source.STATIC, prefix, nextHop)));
}
 
Example 11
Source File: DefaultRouteTable.java    From onos with Apache License 2.0 5 votes vote down vote up
private InternalRouteEvent createRouteEvent(
        InternalRouteEvent.Type type, MultimapEvent<String, RawRoute> event) {
    Collection<? extends RawRoute> currentRoutes = Versioned.valueOrNull(routes.get(event.key()));
    return new InternalRouteEvent(type, new RouteSet(
        id, IpPrefix.valueOf(event.key()), currentRoutes != null ?
        currentRoutes.stream().map(RawRoute::route).collect(Collectors.toSet())
        : Collections.emptySet()));
}
 
Example 12
Source File: McastForwarding.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Process incoming packets.
 *
 * @param context packet processing context
 */
@Override
public void process(PacketContext context) {
    // Stop processing if the packet has been handled, since we
    // can't do any more to it.
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    if (ethPkt == null) {
        return;
    }

    if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4 &&
            ethPkt.getEtherType() != Ethernet.TYPE_IPV6) {
        return;
    }

    if (ethPkt.getEtherType() == Ethernet.TYPE_IPV6) {
        // Ignore ipv6 at the moment.
        return;
    }

    IPv4 ip = (IPv4) ethPkt.getPayload();
    IpAddress saddr = Ip4Address.valueOf(ip.getSourceAddress());
    IpAddress gaddr = IpAddress.valueOf(ip.getDestinationAddress());

    log.debug("Packet ({}, {}) has been punted\n" +
                    "\tingress port: {}\n",
            saddr.toString(),
            gaddr.toString(),
            context.inPacket().receivedFrom().toString());

    // Don't allow PIM/IGMP packets to be handled here.
    byte proto = ip.getProtocol();
    if (proto == IPv4.PROTOCOL_PIM || proto == IPv4.PROTOCOL_IGMP) {
        return;
    }

    IpPrefix spfx = IpPrefix.valueOf(saddr, 32);
    IpPrefix gpfx = IpPrefix.valueOf(gaddr, 32);

    // TODO do we want to add a type for Mcast?
    McastRoute mRoute = new McastRoute(saddr, gaddr, McastRoute.Type.STATIC);

    ConnectPoint ingress = mcastRouteManager.fetchSource(mRoute);

    // An ingress port already exists. Log error.
    if (ingress != null) {
        log.error(McastForwarding.class.getSimpleName() + " received packet which already has a route.");
        return;
    } else {
        //add ingress port
        mcastRouteManager.addSource(mRoute, pkt.receivedFrom());
    }

    ArrayList<ConnectPoint> egressList = (ArrayList<ConnectPoint>) mcastRouteManager.fetchSinks(mRoute);
    //If there are no egress ports set return, otherwise forward the packets to their expected port.
    if (egressList.isEmpty()) {
        return;
    }

    // Send the pack out each of the egress devices & port
    forwardPacketToDst(context, egressList);
}
 
Example 13
Source File: DefaultFlowClassifierTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Checks the operation of equals() methods.
 */
@Test
public void testEquals() {
    // Create same two flow classifier objects.
    final String name = "FlowClassifier1";
    final String description = "FlowClassifier1";
    final String ethType = "IPv4";
    final String protocol = "tcp";
    final int priority = 65535;
    final int minSrcPortRange = 5;
    final int maxSrcPortRange = 10;
    final int minDstPortRange = 5;
    final int maxDstPortRange = 10;
    final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
    final TenantId tenantId = TenantId.tenantId("1");
    final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
    final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0");
    final VirtualPortId virtualSrcPort = VirtualPortId.portId("1");
    final VirtualPortId virtualDstPort = VirtualPortId.portId("2");

    DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
    final FlowClassifier flowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
            .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
            .setProtocol(protocol).setPriority(priority).setMinSrcPortRange(minSrcPortRange)
            .setMaxSrcPortRange(maxSrcPortRange).setMinDstPortRange(minDstPortRange)
            .setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix).setDstIpPrefix(dstIpPrefix)
            .setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();

    flowClassifierBuilder = new DefaultFlowClassifier.Builder();
    final FlowClassifier sameAsFlowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
            .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
            .setProtocol(protocol).setPriority(priority).setMinSrcPortRange(minSrcPortRange)
            .setMaxSrcPortRange(maxSrcPortRange).setMinDstPortRange(minDstPortRange)
            .setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix).setDstIpPrefix(dstIpPrefix)
            .setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();

    // Create different classifier object.
    final String name2 = "FlowClassifier2";
    final String description2 = "FlowClassifier2";
    final String ethType2 = "IPv6";
    final String protocol2 = "udp";
    final int priority2 = 50000;
    final int minSrcPortRange2 = 5;
    final int maxSrcPortRange2 = 10;
    final int minDstPortRange2 = 5;
    final int maxDstPortRange2 = 10;
    final FlowClassifierId flowClassifierId2 = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
    final TenantId tenantId2 = TenantId.tenantId("2");
    final IpPrefix srcIpPrefix2 = IpPrefix.valueOf("0.0.0.0/0");
    final IpPrefix dstIpPrefix2 = IpPrefix.valueOf("10.10.10.10/0");
    final VirtualPortId virtualSrcPort2 = VirtualPortId.portId("3");
    final VirtualPortId virtualDstPort2 = VirtualPortId.portId("4");

    DefaultFlowClassifier.Builder flowClassifierBuilder3 = new DefaultFlowClassifier.Builder();
    final FlowClassifier flowClassifier2 = flowClassifierBuilder3.setFlowClassifierId(flowClassifierId2)
            .setTenantId(tenantId2).setName(name2).setDescription(description2).setEtherType(ethType2)
            .setProtocol(protocol2).setMinSrcPortRange(minSrcPortRange2).setMaxSrcPortRange(maxSrcPortRange2)
            .setMinDstPortRange(minDstPortRange2).setMaxDstPortRange(maxDstPortRange2).setSrcIpPrefix(srcIpPrefix2)
            .setDstIpPrefix(dstIpPrefix2).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2)
            .setPriority(priority2).build();

    new EqualsTester().addEqualityGroup(flowClassifier1, sameAsFlowClassifier1).addEqualityGroup(flowClassifier2)
            .testEquals();
}
 
Example 14
Source File: Dhcp6HandlerImpl.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * extract from dhcp6 packet Prefix prefix provided by dhcp server.
 *
 * @param dhcp6 the dhcp6 payload
 * @return IpPrefix Prefix Delegation prefix, or null if not exists.
 */
private PdPrefixInfo extractPrefix(DHCP6 dhcp6) {
    log.debug("extractPrefix  enters {}", dhcp6);

    // extract prefix
    PdPrefixInfo  pdPrefixInfo = new PdPrefixInfo();

    Ip6Address prefixAddress = null;

    // Extract IPv6 prefix from IA PD option
    Optional<Dhcp6IaPdOption> iaPdOption = dhcp6.getOptions()
            .stream()
            .filter(opt -> opt instanceof Dhcp6IaPdOption)
            .map(opt -> (Dhcp6IaPdOption) opt)
            .findFirst();

    Optional<Dhcp6IaPrefixOption> iaPrefixOption;
    if (iaPdOption.isPresent()) {
        log.debug("IA_PD option found {}", iaPdOption);

        iaPrefixOption = iaPdOption.get().getOptions().stream()
                .filter(opt -> opt instanceof Dhcp6IaPrefixOption)
                .map(opt -> (Dhcp6IaPrefixOption) opt)
                .findFirst();
    } else {
        log.debug("IA_PD option NOT found");

        iaPrefixOption = Optional.empty();
    }
    if (iaPrefixOption.isPresent()) {
        log.debug("IAPrefix Option within IA_PD option found {}", iaPrefixOption);

        prefixAddress = iaPrefixOption.get().getIp6Prefix();
        int prefixLen = (int) iaPrefixOption.get().getPrefixLength();
        log.debug("Prefix length is  {} bits", prefixLen);
        pdPrefixInfo.pdPrefix = IpPrefix.valueOf(prefixAddress, prefixLen);
        pdPrefixInfo.prefTime = iaPrefixOption.get().getPreferredLifetime();
    } else {
        log.debug("Can't find IPv6 prefix from DHCPv6 {}", dhcp6);
        return null;
    }
    return pdPrefixInfo;
}
 
Example 15
Source File: SubnetWebResource.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a collection of subnets from subnetNodes.
 *
 * @param subnetNodes the subnet json node
 * @return subnets a collection of subnets
 */
public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) {
    checkNotNull(subnetNodes, JSON_NOT_NULL);
    checkArgument(subnetNodes.get("enable_dhcp").isBoolean(), "enable_dhcp should be boolean");
    checkArgument(subnetNodes.get("shared").isBoolean(), "shared should be boolean");
    Map<SubnetId, Subnet> subMap = new HashMap<>();
    if (!subnetNodes.hasNonNull("id")) {
        return null;
    }
    SubnetId id = SubnetId.subnetId(subnetNodes.get("id").asText());
    String subnetName = subnetNodes.get("name").asText();
    TenantId tenantId = TenantId
            .tenantId(subnetNodes.get("tenant_id").asText());
    TenantNetworkId networkId = TenantNetworkId
            .networkId(subnetNodes.get("network_id").asText());
    String version = subnetNodes.get("ip_version").asText();
    Version ipVersion;
    switch (version) {
    case "4":
        ipVersion = Version.INET;
        break;
    case "6":
        ipVersion = Version.INET;
        break;
    default:
        throw new IllegalArgumentException("ipVersion should be 4 or 6.");
    }

    IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText());
    IpAddress gatewayIp = IpAddress
            .valueOf(subnetNodes.get("gateway_ip").asText());
    Boolean dhcpEnabled = subnetNodes.get("enable_dhcp").asBoolean();
    Boolean shared = subnetNodes.get("shared").asBoolean();
    JsonNode hostRoutes = subnetNodes.get("host_routes");
    Iterable<HostRoute> hostRoutesIt = jsonNodeToHostRoutes(hostRoutes);
    JsonNode allocationPools = subnetNodes.get("allocation_pools");
    Iterable<AllocationPool> allocationPoolsIt = jsonNodeToAllocationPools(allocationPools);

    Mode ipV6AddressMode = getMode(subnetNodes.get("ipv6_address_mode")
            .asText());
    Mode ipV6RaMode = getMode(subnetNodes.get("ipv6_ra_mode").asText());

    Subnet subnet = new DefaultSubnet(id, subnetName, networkId, tenantId,
                                      ipVersion, cidr, gatewayIp,
                                      dhcpEnabled, shared, Sets.newHashSet(hostRoutesIt),
                                      ipV6AddressMode, ipV6RaMode,
                                      Sets.newHashSet(allocationPoolsIt));
    subMap.put(id, subnet);
    return Collections.unmodifiableCollection(subMap.values());
}
 
Example 16
Source File: DefaultRouteTable.java    From onos with Apache License 2.0 4 votes vote down vote up
Route route() {
    return new Route(source, IpPrefix.valueOf(prefix), IpAddress.valueOf(nextHop), sourceNode);
}
 
Example 17
Source File: DistributedMappingStoreTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up the storage service test harness.
 */
@Before
public void setUp() {
    mappingStore = new DistributedMappingStore();
    mappingStore.storageService = new TestStorageService();
    mappingStore.deviceService = new InternalDeviceServiceAdapter();
    mappingStore.setDelegate(event -> {
    });

    IpPrefix ipPrefix = IpPrefix.valueOf(IP_ADDRESS);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ipPrefix);

    MappingKey key = DefaultMappingKey.builder()
            .withAddress(address)
            .build();

    MappingAction action = MappingActions.noAction();
    MappingTreatment treatment = DefaultMappingTreatment.builder()
            .withAddress(address)
            .setUnicastPriority(10)
            .setUnicastWeight(10)
            .build();

    MappingValue value = DefaultMappingValue.builder()
            .withAction(action)
            .add(treatment)
            .build();

    device1 = new MockDevice(ProviderId.NONE, DEVICE_ID_1, Device.Type.OTHER,
            "foo.inc", "0", "0", "0", null,
            DefaultAnnotations.builder().build());

    device2 = new MockDevice(ProviderId.NONE, DEVICE_ID_2, Device.Type.OTHER,
            "foo.inc", "0", "0", "0", null,
            DefaultAnnotations.builder().build());

    Mapping originalMapping1 = DefaultMapping.builder()
            .forDevice(DEVICE_ID_1)
            .withId(1000L)
            .withKey(key)
            .withValue(value)
            .build();

    Mapping originalMapping2 = DefaultMapping.builder()
            .forDevice(DEVICE_ID_2)
            .withId(2000L)
            .withKey(key)
            .withValue(value)
            .build();

    mapping1 = new DefaultMappingEntry(originalMapping1);
    mapping2 = new DefaultMappingEntry(originalMapping2);

    mappingStore.activate();
}
 
Example 18
Source File: InterfaceConfig.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isValid() {
    for (JsonNode node : array) {
        if (!hasOnlyFields((ObjectNode) node, NAME, IPS, MAC, VLAN,
                VLAN_UNTAGGED, VLAN_TAGGED, VLAN_NATIVE)) {
            return false;
        }

        ObjectNode obj = (ObjectNode) node;

        if (!(isString(obj, NAME, FieldPresence.OPTIONAL) &&
                isMacAddress(obj, MAC, FieldPresence.OPTIONAL) &&
                isIntegralNumber(obj, VLAN, FieldPresence.OPTIONAL, 0, VlanId.MAX_VLAN) &&
                isIntegralNumber(obj, VLAN_UNTAGGED, FieldPresence.OPTIONAL, 0, VlanId.MAX_VLAN) &&
                isIntegralNumber(obj, VLAN_NATIVE, FieldPresence.OPTIONAL, 0, VlanId.MAX_VLAN))) {
            return false;
        }

        for (JsonNode ipNode : node.path(IPS)) {
            if (!ipNode.isTextual() || IpPrefix.valueOf(ipNode.asText()) == null) {
                return false;
            }
        }

        checkArgument(!hasField(obj, VLAN_TAGGED) ||
                        (node.path(VLAN_TAGGED).isArray() && node.path(VLAN_TAGGED).size() >= 1),
                "%s must be an array with at least one element", VLAN_TAGGED);

        for (JsonNode vlanNode : node.path(VLAN_TAGGED)) {
            checkArgument(vlanNode.isInt() &&
                    vlanNode.intValue() >= 0 &&  vlanNode.intValue() <= VlanId.MAX_VLAN,
                    "Invalid VLAN ID %s in %s", vlanNode.intValue(), VLAN_TAGGED);
        }

        checkArgument(!hasField(obj, VLAN_UNTAGGED) ||
                !(hasField(obj, VLAN_TAGGED) || hasField(obj, VLAN_NATIVE)),
                "%s and %s should not be used when %s is set", VLAN_TAGGED, VLAN_NATIVE, VLAN_UNTAGGED);

        checkArgument(!hasField(obj, VLAN_TAGGED) || !hasField(obj, VLAN_UNTAGGED),
                "%s should not be used when %s is set", VLAN_UNTAGGED, VLAN_TAGGED);

        checkArgument(!hasField(obj, VLAN_NATIVE) || hasField(obj, VLAN_TAGGED),
                "%s should not be used alone without %s", VLAN_NATIVE, VLAN_TAGGED);

        checkArgument(!hasField(obj, VLAN_NATIVE) || !hasField(obj, VLAN_TAGGED) ||
                !getVlans(obj, VLAN_TAGGED).contains(getVlan(obj, VLAN_NATIVE)),
                "%s cannot be one of the VLANs configured in %s", VLAN_NATIVE, VLAN_TAGGED);
    }
    return true;
}
 
Example 19
Source File: MappingTestMocks.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public MappingAddress address() {
    IpPrefix ip = IpPrefix.valueOf(IP);
    return MappingAddresses.ipv4MappingAddress(ip);
}
 
Example 20
Source File: LispRadixTreeDatabase.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains the IP prefix from LISP EID record.
 *
 * @param eidRecord LISP EID record
 * @return IP prefix object
 */
private IpPrefix getIpPrefix(LispEidRecord eidRecord) {
    return IpPrefix.valueOf(cidrfy(eidRecord));
}