Search in sources :

Example 6 with ExtensionPropertyException

use of org.onosproject.net.flow.instructions.ExtensionPropertyException in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildExtension.

/**
 * Returns tunnel destination extension treatment object.
 *
 * @param deviceService driver service
 * @param deviceId device id to apply this treatment
 * @param remoteIp tunnel destination ip address
 * @return extension treatment
 */
public static ExtensionTreatment buildExtension(DeviceService deviceService, DeviceId deviceId, Ip4Address remoteIp) {
    Device device = deviceService.getDevice(deviceId);
    if (!checkTreatmentResolver(device)) {
        return null;
    }
    if (device == null) {
        return null;
    }
    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
    try {
        treatment.setPropertyValue(TUNNEL_DST, remoteIp);
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.warn("Failed to get tunnelDst extension treatment for {} " + "because of {}", deviceId, e);
        return null;
    }
}
Also used : Device(org.onosproject.net.Device) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 7 with ExtensionPropertyException

use of org.onosproject.net.flow.instructions.ExtensionPropertyException in project onos by opennetworkinglab.

the class AbstractExtension method setPropertyValue.

@Override
public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException {
    Class<?> clazz = this.getClass();
    try {
        Field field = clazz.getDeclaredField(key);
        field.setAccessible(true);
        field.set(this, value);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new ExtensionPropertyException(INVALID_KEY + key);
    }
}
Also used : Field(java.lang.reflect.Field) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 8 with ExtensionPropertyException

use of org.onosproject.net.flow.instructions.ExtensionPropertyException in project onos by opennetworkinglab.

the class AbstractExtension method getPropertyValue.

@Override
public <T> T getPropertyValue(String key) throws ExtensionPropertyException {
    Class<?> clazz = this.getClass();
    try {
        Field field = clazz.getDeclaredField(key);
        field.setAccessible(true);
        @SuppressWarnings("unchecked") T result = (T) field.get(this);
        return result;
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new ExtensionPropertyException(INVALID_KEY + key);
    } catch (ClassCastException e) {
        throw new ExtensionPropertyException(INVALID_TYPE + key);
    }
}
Also used : Field(java.lang.reflect.Field) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 9 with ExtensionPropertyException

use of org.onosproject.net.flow.instructions.ExtensionPropertyException in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildExtension.

/**
 * Returns tunnel destination extension treatment object.
 *
 * @param deviceService driver service
 * @param deviceId device id to apply this treatment
 * @param remoteIp tunnel destination ip address
 * @return extension treatment
 */
public static ExtensionTreatment buildExtension(DeviceService deviceService, DeviceId deviceId, Ip4Address remoteIp) {
    Device device = deviceService.getDevice(deviceId);
    if (!checkTreatmentResolver(device)) {
        return null;
    }
    if (device == null) {
        return null;
    }
    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
    try {
        treatment.setPropertyValue(TUNNEL_DST, remoteIp);
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.warn("Failed to get tunnelDst extension treatment for {} " + "because of {}", deviceId, e);
        return null;
    }
}
Also used : Device(org.onosproject.net.Device) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 10 with ExtensionPropertyException

use of org.onosproject.net.flow.instructions.ExtensionPropertyException in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildLoadExtension.

/**
 * Returns the nicira load extension treatment.
 *
 * @param device        device instance
 * @param field         field code
 * @param value         value to load
 * @return load extension treatment
 */
public static ExtensionTreatment buildLoadExtension(Device device, long field, long value) {
    if (!checkTreatmentResolver(device)) {
        return null;
    }
    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_LOAD.type());
    int ofsNbits = OFF_SET_BIT << 6 | (REMAINDER_BIT - 1);
    try {
        treatment.setPropertyValue(OFF_SET_N_BITS, ofsNbits);
        treatment.setPropertyValue(DESTINATION, field);
        treatment.setPropertyValue(VALUE, value);
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.error("Failed to set nicira load extension treatment for {}", device.id());
        return null;
    }
}
Also used : ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Aggregations

ExtensionPropertyException (org.onosproject.net.flow.instructions.ExtensionPropertyException)13 ExtensionTreatmentResolver (org.onosproject.net.behaviour.ExtensionTreatmentResolver)11 ExtensionTreatment (org.onosproject.net.flow.instructions.ExtensionTreatment)11 Device (org.onosproject.net.Device)6 Field (java.lang.reflect.Field)2 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)1 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)1 Driver (org.onosproject.net.driver.Driver)1 DriverHandler (org.onosproject.net.driver.DriverHandler)1