Search in sources :

Example 96 with Ip4Address

use of org.onlab.packet.Ip4Address in project aaa by opencord.

the class SamplePacketCustomizer method customizePacket.

/**
 * Customize the packet as per specific Setup or RADIUS
 * server requirements.
 *
 * @param inPkt RADIUS packet to be customized
 * @param eapPacket Incoming packet containing EAP for which this the
 *                  RADIUS message is being created
 * @return Customized RADIUS packet
 */
@Override
public RADIUS customizePacket(RADIUS inPkt, InboundPacket eapPacket) {
    Port p = customInfo.deviceService().getPort(eapPacket.receivedFrom());
    String id = p.annotations().value(AnnotationKeys.PORT_NAME);
    log.info("Customizing packet Port received for {}", id);
    if (customInfo.subscriberService() == null) {
        log.warn(SADIS_NOT_RUNNING);
        return inPkt;
    }
    SubscriberAndDeviceInformation subscriber = customInfo.subscriberService().get(id);
    if (subscriber == null) {
        log.warn("No subscriber found with id {}", id);
        return inPkt;
    }
    String nasPortId = subscriber.nasPortId();
    Ethernet ethPkt = eapPacket.parsed();
    MacAddress srcMac = ethPkt.getSourceMAC();
    // Get the nasId from subscriber service using the Serial Number
    String serialNo = customInfo.deviceService().getDevice(eapPacket.receivedFrom().deviceId()).serialNumber();
    log.info("SampleRadiusCustomizer serial = {}", serialNo);
    SubscriberAndDeviceInformation deviceInfo = customInfo.subscriberService().get(serialNo);
    if (deviceInfo == null) {
        log.warn("No Device found with SN {}", serialNo);
        return inPkt;
    }
    String nodeName = deviceInfo.nasId();
    Ip4Address ipAddress = deviceInfo.ipAddress();
    if (nasPortId == null || nodeName == null || ipAddress == null) {
        log.warn("Insufficient data to Customize packet" + " : nasPortId = {}, nodeName = {}, ipAddress = {}", nasPortId, nodeName, ipAddress);
        return inPkt;
    }
    log.info("Setting nasId={} nasPortId{}", nodeName, nasPortId);
    if (updateNasIp()) {
        inPkt.updateAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, deviceInfo.ipAddress().toOctets());
    }
    inPkt.setAttribute(RADIUSAttribute.RADIUS_ATTR_CALLING_STATION_ID, srcMac.toBytes());
    // Check value - 16 was used in PoC2, as per PoC3 TS value should be 15
    inPkt.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_PORT_TYPE, ByteBuffer.allocate(4).putInt(15).array());
    inPkt.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_PORT, ByteBuffer.allocate(4).putInt((int) p.number().toLong()).array());
    // Check - If this is needed, worked with this value in PoC2
    inPkt.setAttribute(RADIUSAttribute.RADIUS_ATTR_ACCT_SESSION_ID, "023:27:46:00000".getBytes());
    inPkt.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_ID, nodeName.getBytes());
    inPkt.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_PORT_ID, nasPortId.getBytes());
    return inPkt;
}
Also used : Port(org.onosproject.net.Port) Ethernet(org.onlab.packet.Ethernet) Ip4Address(org.onlab.packet.Ip4Address) SubscriberAndDeviceInformation(org.opencord.sadis.SubscriberAndDeviceInformation) MacAddress(org.onlab.packet.MacAddress)

Example 97 with Ip4Address

use of org.onlab.packet.Ip4Address in project aaa by opencord.

the class SamplePacketCustomizer method customizeEthernetIPHeaders.

/**
 * Customize the Ethernet header as per specific Setup or RADIUS
 * server requirements.
 *
 * @param inPkt Ethernet packet to be changed
 * @param eapPacket Incoming packet containing EAP for which this the
 *                  RADIUS message is being created
 * @return Changed Ethernet packet
 */
@Override
public Ethernet customizeEthernetIPHeaders(Ethernet inPkt, InboundPacket eapPacket) {
    String serialNo = customInfo.deviceService().getDevice(eapPacket.receivedFrom().deviceId()).serialNumber();
    log.info("SampleRadiusCustomzer customizer serial = {}", serialNo);
    if (customInfo.subscriberService() == null) {
        log.warn(SADIS_NOT_RUNNING);
        return inPkt;
    }
    SubscriberAndDeviceInformation deviceInfo = customInfo.subscriberService().get(serialNo);
    if (deviceInfo == null) {
        log.warn("No Device found with SN {}", serialNo);
        return inPkt;
    }
    MacAddress macAddress = deviceInfo.hardwareIdentifier();
    Ip4Address ipAddress = deviceInfo.ipAddress();
    if (macAddress == null || ipAddress == null) {
        log.warn("Insufficient data to Customize Ethernet IP Headers" + " : hardwareIdentifier = {}, ipAddress = {}", macAddress, ipAddress);
        return inPkt;
    }
    inPkt.setSourceMACAddress(macAddress);
    IPv4 ipv4Packet = (IPv4) inPkt.getPayload();
    ipv4Packet.setSourceAddress(ipAddress.toString());
    inPkt.setPayload(ipv4Packet);
    return inPkt;
}
Also used : IPv4(org.onlab.packet.IPv4) Ip4Address(org.onlab.packet.Ip4Address) SubscriberAndDeviceInformation(org.opencord.sadis.SubscriberAndDeviceInformation) MacAddress(org.onlab.packet.MacAddress)

Example 98 with Ip4Address

use of org.onlab.packet.Ip4Address in project fabric-tna by stratum.

the class FabricUpfTranslator method fabricEntryToUpfTerminationDownlink.

/**
 * Translate a fabric.p4 termination table entry to a downlink UpfTermination instance for easier handling.
 *
 * @param entry the fabric.p4 entry to translate
 * @return the corresponding UpfTerminationDownlink
 * @throws UpfProgrammableException if the entry cannot be translated
 */
public UpfTerminationDownlink fabricEntryToUpfTerminationDownlink(FlowRule entry) throws UpfProgrammableException {
    assertTableId(entry, FABRIC_INGRESS_UPF_DOWNLINK_TERMINATIONS);
    UpfTerminationDownlink.Builder builder = UpfTerminationDownlink.builder();
    Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
    PiCriterion match = matchActionPair.getLeft();
    PiAction action = (PiAction) matchActionPair.getRight();
    if (!FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_UE_SESSION_ID) || !FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_APP_ID)) {
        throw new UpfProgrammableException("Malformed downlink termination from dataplane!: " + entry);
    }
    // Match keys
    Ip4Address ueSessionId = FabricUpfTranslatorUtil.getFieldAddress(match, HDR_UE_SESSION_ID);
    builder.withUeSessionId(ueSessionId);
    byte applicationId = FabricUpfTranslatorUtil.getFieldByte(match, HDR_APP_ID);
    builder.withApplicationId(applicationId);
    PiActionId actionId = action.id();
    builder.withCounterId(FabricUpfTranslatorUtil.getParamInt(action, CTR_ID));
    if (actionId.equals(FABRIC_INGRESS_UPF_DOWNLINK_DROP)) {
        builder.needsDropping(true);
    } else {
        builder.withTeid(FabricUpfTranslatorUtil.getParamInt(action, TEID)).withQfi(FabricUpfTranslatorUtil.getParamByte(action, QFI)).withAppMeterIdx(FabricUpfTranslatorUtil.getParamShort(action, APP_METER_IDX));
        if (actionId.equals(FABRIC_INGRESS_UPF_DOWNLINK_FWD_ENCAP)) {
            builder.withTrafficClass(FabricUpfTranslatorUtil.getParamByte(action, TC));
        }
    }
    return builder.build();
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) PiActionId(org.onosproject.net.pi.model.PiActionId) UpfTerminationDownlink(org.onosproject.net.behaviour.upf.UpfTerminationDownlink) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) Ip4Address(org.onlab.packet.Ip4Address) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

Ip4Address (org.onlab.packet.Ip4Address)98 Test (org.junit.Test)29 Ip4Prefix (org.onlab.packet.Ip4Prefix)20 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)15 MacAddress (org.onlab.packet.MacAddress)15 ArrayList (java.util.ArrayList)14 Ip6Address (org.onlab.packet.Ip6Address)14 IpAddress (org.onlab.packet.IpAddress)13 LinkedList (java.util.LinkedList)12 Ethernet (org.onlab.packet.Ethernet)12 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)12 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)12 AsPath (org.onosproject.bgpio.types.AsPath)12 BgpHeader (org.onosproject.bgpio.types.BgpHeader)12 BgpValueType (org.onosproject.bgpio.types.BgpValueType)12 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)12 Med (org.onosproject.bgpio.types.Med)12 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)12 Origin (org.onosproject.bgpio.types.Origin)12 OriginType (org.onosproject.bgpio.types.Origin.OriginType)12