Search in sources :

Example 6 with SubscriberAndDeviceInformation

use of org.opencord.sadis.SubscriberAndDeviceInformation 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 7 with SubscriberAndDeviceInformation

use of org.opencord.sadis.SubscriberAndDeviceInformation 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)

Aggregations

SubscriberAndDeviceInformation (org.opencord.sadis.SubscriberAndDeviceInformation)7 Port (org.onosproject.net.Port)4 Ip4Address (org.onlab.packet.Ip4Address)3 Device (org.onosproject.net.Device)3 Ethernet (org.onlab.packet.Ethernet)2 IPv4 (org.onlab.packet.IPv4)2 MacAddress (org.onlab.packet.MacAddress)2 TpPort (org.onlab.packet.TpPort)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 PortNumber (org.onosproject.net.PortNumber)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Argument (org.apache.karaf.shell.api.action.Argument)1 Command (org.apache.karaf.shell.api.action.Command)1 Completion (org.apache.karaf.shell.api.action.Completion)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 UDP (org.onlab.packet.UDP)1