Search in sources :

Example 1 with Type

use of org.onosproject.net.Port.Type in project onos by opennetworkinglab.

the class TextBlockParserCisco method findPortInfo.

/**
 * Creates the port information object.
 * @param interfaceTree the interfaces as plain text
 * @return the Port description object
 */
private static DefaultPortDescription findPortInfo(String interfaceTree) {
    String[] textStr = interfaceTree.split(NEWLINE_SPLITTER);
    String[] firstLine = textStr[0].split(SPACE);
    String firstWord = firstLine[0];
    Type type = getPortType(textStr);
    boolean isEnabled = getIsEnabled(textStr);
    String port = getPort(textStr);
    long portSpeed = getPortSpeed(textStr);
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, firstWord);
    return "-1".equals(port) ? null : DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(port)).isEnabled(isEnabled).type(type).portSpeed(portSpeed).annotations(annotations.build()).build();
}
Also used : Type(org.onosproject.net.Port.Type) DefaultAnnotations(org.onosproject.net.DefaultAnnotations)

Example 2 with Type

use of org.onosproject.net.Port.Type in project onos by opennetworkinglab.

the class PortCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: Result of {@link Port#element()} returned Port object,
 *       is not a full Device object.
 *       Only it's DeviceId can be used.
 */
@Override
public Port decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    DeviceId did = DeviceId.deviceId(json.get(ELEMENT).asText());
    Device device = new DummyDevice(did);
    PortNumber number = portNumber(json.get(PORT_NAME).asText());
    boolean isEnabled = json.get(IS_ENABLED).asBoolean();
    Type type = Type.valueOf(json.get(TYPE).asText().toUpperCase());
    long portSpeed = json.get(PORT_SPEED).asLong();
    Annotations annotations = extractAnnotations(json, context);
    return new DefaultPort(device, number, isEnabled, type, portSpeed, annotations);
}
Also used : Type(org.onosproject.net.Port.Type) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort)

Example 3 with Type

use of org.onosproject.net.Port.Type in project onos by opennetworkinglab.

the class JuniperUtils method parsePhysicalInterface.

/**
 * Parses {@literal physical-interface} tree.
 *
 * @param portDescriptions list to populate Ports found parsing configuration
 * @param phyIntf physical-interface
 */
private static void parsePhysicalInterface(List<PortDescription> portDescriptions, HierarchicalConfiguration phyIntf) {
    Builder annotations = DefaultAnnotations.builder();
    PortNumber portNumber = portNumber(phyIntf.getString(SNMP_INDEX));
    String phyPortName = phyIntf.getString(NAME);
    if (portNumber == null) {
        log.debug("Skipping physical-interface {}, no PortNumer", phyPortName);
        log.trace("  {}", phyIntf);
        return;
    }
    setIfNonNull(annotations, AnnotationKeys.PORT_NAME, phyPortName);
    setIfNonNull(annotations, AnnotationKeys.PORT_MAC, phyIntf.getString("current-physical-address"));
    setIfNonNull(annotations, AK_IF_TYPE, phyIntf.getString(IF_TYPE));
    setIfNonNull(annotations, AK_DESCRIPTION, phyIntf.getString("description"));
    boolean opUp = phyIntf.getString("oper-status", "down").equals("up");
    annotations.set(AK_OPER_STATUS, toUpDown(opUp));
    boolean admUp = phyIntf.getString("admin-status", "down").equals("up");
    annotations.set(AK_ADMIN_STATUS, toUpDown(admUp));
    long portSpeed = toMbps(phyIntf.getString(SPEED));
    Type portType = phyIntf.getString(IF_MEDIA_TYPE, COPPER).equalsIgnoreCase(FIBER) ? Type.FIBER : Type.COPPER;
    portDescriptions.add(DefaultPortDescription.builder().withPortNumber(portNumber).isEnabled(admUp && opUp).type(portType).portSpeed(portSpeed).annotations(annotations.build()).build());
    // parse each logical Interface
    for (HierarchicalConfiguration logIntf : phyIntf.configurationsAt("logical-interface")) {
        if (logIntf == null) {
            continue;
        }
        PortNumber lPortNumber = safePortNumber(logIntf.getString(SNMP_INDEX));
        if (lPortNumber == null) {
            log.debug("Skipping logical-interface {} under {}, no PortNumer", logIntf.getString(NAME), phyPortName);
            log.trace("  {}", logIntf);
            continue;
        }
        Builder lannotations = DefaultAnnotations.builder();
        setIfNonNull(lannotations, AnnotationKeys.PORT_NAME, logIntf.getString(NAME));
        setIfNonNull(lannotations, AK_PHYSICAL_PORT_NAME, phyPortName);
        String afName = logIntf.getString("address-family.address-family-name");
        String address = logIntf.getString("address-family.interface-address.ifa-local");
        if (afName != null && address != null) {
            // e.g., inet : IPV4, inet6 : IPV6
            setIfNonNull(lannotations, afName, address);
        }
        // preserving former behavior
        setIfNonNull(lannotations, AK_IP, logIntf.getString("address-family.interface-address.ifa-local"));
        setIfNonNull(lannotations, AK_ENCAPSULATION, logIntf.getString("encapsulation"));
        // TODO confirm if this is correct.
        // Looking at sample data,
        // it seemed all logical loop-back interfaces were down
        boolean lEnabled = logIntf.getString("if-config-flags.iff-up") != null;
        portDescriptions.add(DefaultPortDescription.builder().withPortNumber(lPortNumber).isEnabled(admUp && opUp && lEnabled).type(portType).portSpeed(portSpeed).annotations(lannotations.build()).build());
    }
}
Also used : Type(org.onosproject.net.Port.Type) Builder(org.onosproject.net.DefaultAnnotations.Builder) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) PortNumber(org.onosproject.net.PortNumber) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 4 with Type

use of org.onosproject.net.Port.Type in project onos by opennetworkinglab.

the class OpticalPortOperator method combine.

/**
 * Generates a PortDescription containing fields from a PortDescription and
 * an OpticalPortConfig.
 *
 * @param cp {@link ConnectPoint} representing the port.
 * @param descr input {@link PortDescription}
 * @return Combined {@link PortDescription}
 */
@Override
public PortDescription combine(ConnectPoint cp, PortDescription descr) {
    checkNotNull(cp);
    // must be removed if we need type override
    if (descr != null && !optical.contains(descr.type())) {
        return descr;
    }
    OpticalPortConfig opc = lookupConfig(cp);
    if (descr == null || opc == null) {
        return descr;
    }
    PortNumber number = descr.portNumber();
    // handle PortNumber "name" portion
    if (!opc.name().isEmpty()) {
        number = PortNumber.portNumber(descr.portNumber().toLong(), opc.name());
    }
    // handle additional annotations
    SparseAnnotations annotations = combine(opc, descr.annotations());
    // (Future work) handle type overwrite?
    Type type = firstNonNull(opc.type(), descr.type());
    if (type != descr.type()) {
        // TODO: Do we need to be able to overwrite Port.Type?
        log.warn("Port type overwrite requested for {}. Ignoring.", cp);
    }
    return updateDescription(number, annotations, descr);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Type(org.onosproject.net.Port.Type) PortNumber(org.onosproject.net.PortNumber)

Aggregations

Type (org.onosproject.net.Port.Type)4 PortNumber (org.onosproject.net.PortNumber)3 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)2 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 EqualsBuilder (org.apache.commons.lang3.builder.EqualsBuilder)1 HashCodeBuilder (org.apache.commons.lang3.builder.HashCodeBuilder)1 XmlConfigParser.loadXmlString (org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)1 Annotations (org.onosproject.net.Annotations)1 Builder (org.onosproject.net.DefaultAnnotations.Builder)1 DefaultDevice (org.onosproject.net.DefaultDevice)1 DefaultPort (org.onosproject.net.DefaultPort)1 Device (org.onosproject.net.Device)1 DeviceId (org.onosproject.net.DeviceId)1 SparseAnnotations (org.onosproject.net.SparseAnnotations)1