Search in sources :

Example 6 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class ReactiveRoutingFib method hostToHostIntentGenerator.

/**
 * Generates MultiPointToSinglePointIntent for both source host and
 * destination host located in local SDN network.
 *
 * @param dstIpAddress the destination IP address
 * @param dstConnectPoint the destination host connect point
 * @param dstMacAddress the MAC address of destination host
 * @param srcConnectPoint the connect point where packet-in from
 * @return the generated MultiPointToSinglePointIntent
 */
private MultiPointToSinglePointIntent hostToHostIntentGenerator(IpAddress dstIpAddress, ConnectPoint dstConnectPoint, MacAddress dstMacAddress, ConnectPoint srcConnectPoint) {
    checkNotNull(dstIpAddress);
    checkNotNull(dstConnectPoint);
    checkNotNull(dstMacAddress);
    checkNotNull(srcConnectPoint);
    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    ingressPoints.add(new FilteredConnectPoint(srcConnectPoint));
    IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (dstIpAddress.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        selector.matchIPDst(dstIpPrefix);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        selector.matchIPv6Dst(dstIpPrefix);
    }
    // Rewrite the destination MAC address
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(dstMacAddress);
    Key key = Key.of(dstIpPrefix.toString(), appId);
    int priority = dstIpPrefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(ingressPoints).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).priority(priority).constraints(CONSTRAINTS).build();
    log.trace("Generates ConnectivityHostToHost = {} ", intent);
    return intent;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key) ConnectPoint(org.onosproject.net.ConnectPoint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 7 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class VbngConfigurationManager method readConfiguration.

/**
 * Reads virtual BNG information contained in configuration file.
 *
 * @param configFilename the name of the configuration file for the virtual
 * BNG application
 */
private void readConfiguration(String configFilename) {
    File configFile = new File(CONFIG_DIR, configFilename);
    ObjectMapper mapper = new ObjectMapper();
    try {
        log.info("Loading config: {}", configFile.getAbsolutePath());
        VbngConfiguration config = mapper.readValue(configFile, VbngConfiguration.class);
        for (IpPrefix prefix : config.getLocalPublicIpPrefixes()) {
            localPublicIpPrefixes.put(prefix, true);
        }
        nextHopIpAddress = config.getNextHopIpAddress();
        macOfPublicIpAddresses = config.getPublicFacingMac();
        xosIpAddress = config.getXosIpAddress();
        xosRestPort = config.getXosRestPort();
        nodeToPort = config.getHosts();
    } catch (FileNotFoundException e) {
        log.warn("Configuration file not found: {}", configFileName);
    } catch (IOException e) {
        log.error("Error loading configuration", e);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class VbngConfigurationManager method assignSpecifiedPublicIp.

@Override
public synchronized boolean assignSpecifiedPublicIp(IpAddress publicIpAddress, IpAddress privateIpAddress) {
    // Judge whether this public IP address is in our public IP
    // prefix/address list.
    boolean isPublicIpExist = false;
    for (Entry<IpPrefix, Boolean> prefix : localPublicIpPrefixes.entrySet()) {
        if (prefix.getKey().contains(publicIpAddress)) {
            isPublicIpExist = true;
            // Judge whether this public IP address is already assigned
            if (!prefix.getValue() || isAssignedPublicIpAddress(publicIpAddress)) {
                log.info("The public IP address {} is already assigned, " + "and not available.", publicIpAddress);
                return false;
            }
            // The public IP address is still available
            // Store the mapping from private IP address to public IP address
            ipAddressMap.put(privateIpAddress, publicIpAddress);
            // Update the prefix status
            if (prefix.getKey().prefixLength() == 32) {
                updateIpPrefixStatus(prefix.getKey(), false);
                return true;
            }
            // Judge whether the prefix of this public IP address is used
            // up, if so, update the IP prefix status.
            double prefixLen = prefix.getKey().prefixLength();
            int availableIpNum = (int) Math.pow(2, IpPrefix.MAX_INET_MASK_LENGTH - prefixLen) - 1;
            int usedIpNum = 0;
            for (Entry<IpAddress, IpAddress> ipAddressMapEntry : ipAddressMap.entrySet()) {
                if (prefix.getKey().contains(ipAddressMapEntry.getValue())) {
                    usedIpNum = usedIpNum + 1;
                }
            }
            if (usedIpNum == availableIpNum) {
                updateIpPrefixStatus(prefix.getKey(), false);
            }
            return true;
        }
    }
    log.info("The public IP address {} retrieved from XOS mapping does " + "not exist", publicIpAddress);
    return false;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 9 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class VbngConfigurationManager method recycleAssignedPublicIpAddress.

@Override
public synchronized IpAddress recycleAssignedPublicIpAddress(IpAddress privateIpAddress) {
    IpAddress publicIpAddress = ipAddressMap.remove(privateIpAddress);
    if (publicIpAddress == null) {
        return null;
    }
    Iterator<Entry<IpPrefix, Boolean>> prefixes = localPublicIpPrefixes.entrySet().iterator();
    while (prefixes.hasNext()) {
        Entry<IpPrefix, Boolean> prefixEntry = prefixes.next();
        if (prefixEntry.getKey().contains(publicIpAddress) && !prefixEntry.getValue()) {
            updateIpPrefixStatus(prefixEntry.getKey(), true);
        }
    }
    log.info("[DELETE] Private IP to Public IP mapping: {} --> {}", privateIpAddress, publicIpAddress);
    return publicIpAddress;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Entry(java.util.Map.Entry) IpAddress(org.onlab.packet.IpAddress)

Example 10 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class BgpUpdateLinkStateAttrTest method bgpUpdateMessageTest9.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrIsIsAdminstGrp.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest9() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x7b, // origin
    0x04, // origin
    0x01, // origin
    0x01, // origin
    0x00, // as_path
    0x40, // as_path
    0x02, // as_path
    0x04, // as_path
    0x02, // as_path
    0x01, // as_path
    (byte) 0xfd, // as_path
    (byte) 0xe9, // med
    (byte) 0x80, // med
    0x04, // med
    0x04, // med
    0x00, // med
    0x00, // med
    0x00, // med
    0x00, // mpreach
    (byte) 0x80, // mpreach
    0x0e, // mpreach
    0x53, // mpreach
    0x40, // mpreach
    0x04, // mpreach
    0x47, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
    0x00, // link nlri
    (byte) 0x95, // link nlri
    0x02, // link nlri
    0x50, // link nlri
    0x21, // linkstate attr
    (byte) 0x80, // linkstate attr
    0x1d, // linkstate attr
    0x10, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    0x00, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    (byte) 0x15, // BgpAttrNodeRouterId
    0x15, // BgpAttrNodeRouterId
    0x15, // BgpAttrNodeRouterId
    0x15, 0x04, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, // BgpLinkAttrIsIsAdminstGrp
    0x00 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;
    byte[] marker = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
    assertThat(other.getHeader().getMarker(), is(marker));
    assertThat(other.getHeader().getType(), is((byte) 2));
    assertThat(other.getHeader().getLength(), is((short) 150));
    ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
    byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
    while (listIterator1.hasNext()) {
        IpPrefix testPrefixValue = listIterator1.next();
        assertThat(testPrefixValue.prefixLength(), is((int) 24));
        assertThat(testPrefixValue.address().toOctets(), is(prefix));
    }
    BgpValueType testPathAttribute = null;
    Origin origin;
    AsPath aspath;
    Med med;
    MpReachNlri mpReach;
    LinkStateAttributes linkStateAttr;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    BgpPathAttributes pathAttribute = other.bgpPathAttributes();
    pathAttributeList = pathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
    OriginType originValue = OriginType.IGP;
    testPathAttribute = listIterator.next();
    origin = (Origin) testPathAttribute;
    assertThat(origin.origin(), is(originValue));
    testPathAttribute = listIterator.next();
    aspath = (AsPath) testPathAttribute;
    ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
    assertThat(listIterator2.next(), is((short) 65001));
    testPathAttribute = listIterator.next();
    med = (Med) testPathAttribute;
    assertThat(med.med(), is(0));
    testPathAttribute = listIterator.next();
    mpReach = (MpReachNlri) testPathAttribute;
    assertThat(mpReach.mpReachNlriLen(), is((int) 83));
    assertThat(mpReach.getType(), is((short) 14));
    List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
    testMpReachNlri = mpReach.mpReachNlri();
    ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
    BgpLSNlri testnlri = list1.next();
    NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
    ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
    assertThat(testnlri.getIdentifier(), is((long) 0));
    assertThat(testnlri.getNlriType(), is(nlriType));
    assertThat(testnlri.getProtocolId(), is(protocolId));
    testPathAttribute = listIterator.next();
    linkStateAttr = (LinkStateAttributes) testPathAttribute;
    assertThat(linkStateAttr.getType(), is((short) 29));
    ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
    byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
    Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
    assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
    assertThat(((BgpLinkAttrIsIsAdminstGrp) list.next()).linkAttrIsIsAdminGrp(), is((long) 0));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) Ip4Address(org.onlab.packet.Ip4Address) BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) BgpValueType(org.onosproject.bgpio.types.BgpValueType) OriginType(org.onosproject.bgpio.types.Origin.OriginType) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)131 Test (org.junit.Test)42 IpAddress (org.onlab.packet.IpAddress)36 LinkedList (java.util.LinkedList)24 TrafficSelector (org.onosproject.net.flow.TrafficSelector)24 MacAddress (org.onlab.packet.MacAddress)23 ConnectPoint (org.onosproject.net.ConnectPoint)23 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)22 BgpHeader (org.onosproject.bgpio.types.BgpHeader)22 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)21 AsPath (org.onosproject.bgpio.types.AsPath)21 BgpValueType (org.onosproject.bgpio.types.BgpValueType)21 Origin (org.onosproject.bgpio.types.Origin)21 OriginType (org.onosproject.bgpio.types.Origin.OriginType)21 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)21 Med (org.onosproject.bgpio.types.Med)20 VlanId (org.onlab.packet.VlanId)19 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)18