All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.projectfloodlight.openflow.protocol.ver15.OFStatV6Ver15 Maven / Gradle / Ivy

Go to download

OpenFlowJ API supporting OpenFlow versions 1.0 through 1.5.1, generated by LoxiGen

The newest version!
// Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
// Copyright (c) 2011, 2012 Open Networking Foundation
// Copyright (c) 2012, 2013 Big Switch Networks, Inc.
// This library was generated by the LoxiGen Compiler.
// See the file LICENSE.txt which should have been included in the source distribution

// Automatically generated by LOXI from template of_class.java
// Do not modify

package org.projectfloodlight.openflow.protocol.ver15;

import org.projectfloodlight.openflow.protocol.*;
import org.projectfloodlight.openflow.protocol.action.*;
import org.projectfloodlight.openflow.protocol.actionid.*;
import org.projectfloodlight.openflow.protocol.bsntlv.*;
import org.projectfloodlight.openflow.protocol.errormsg.*;
import org.projectfloodlight.openflow.protocol.meterband.*;
import org.projectfloodlight.openflow.protocol.instruction.*;
import org.projectfloodlight.openflow.protocol.instructionid.*;
import org.projectfloodlight.openflow.protocol.match.*;
import org.projectfloodlight.openflow.protocol.stat.*;
import org.projectfloodlight.openflow.protocol.oxm.*;
import org.projectfloodlight.openflow.protocol.oxs.*;
import org.projectfloodlight.openflow.protocol.queueprop.*;
import org.projectfloodlight.openflow.types.*;
import org.projectfloodlight.openflow.util.*;
import org.projectfloodlight.openflow.exceptions.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Iterator;
import com.google.common.collect.AbstractIterator;
import java.util.Set;
import io.netty.buffer.ByteBuf;
import com.google.common.hash.PrimitiveSink;
import com.google.common.hash.Funnel;

class OFStatV6Ver15 implements OFStatV6 {
    private static final Logger logger = LoggerFactory.getLogger(OFStatV6Ver15.class);
    // version: 1.5
    final static byte WIRE_VERSION = 6;
    final static int MINIMUM_LENGTH = 4;
    // maximum OF message length: 16 bit, unsigned
    final static int MAXIMUM_LENGTH = 0xFFFF;

        private final static OFOxsList DEFAULT_OXS_FIELDS = OFOxsList.EMPTY;

    // OF message fields
    private final OFOxsList oxsFields;
//
    // Immutable default instance
    final static OFStatV6Ver15 DEFAULT = new OFStatV6Ver15(
        DEFAULT_OXS_FIELDS
    );

    // package private constructor - used by readers, builders, and factory
    OFStatV6Ver15(OFOxsList oxsFields) {
        if(oxsFields == null) {
            throw new NullPointerException("OFStatV6Ver15: property oxsFields cannot be null");
        }
        this.oxsFields = oxsFields;
    }

    // Accessors for OF message fields
    @Override
    public OFOxsList getOxsFields() {
        return oxsFields;
    }

    @Override
    public OFVersion getVersion() {
        return OFVersion.OF_15;
    }



    @Override
    public > F get(StatField field)
            throws UnsupportedOperationException {
        if (!supports(field))
            throw new UnsupportedOperationException("OFStatV6Ver15 does not support statistics on field " + field.getName());

        OFOxs oxs = this.oxsFields.get(field);

        if (oxs == null)
            return null;

        return oxs.getValue();
    }

    @Override
    public Iterable> getStatFields() {
        return new Iterable>() {
            public Iterator> iterator() {
                return new StatFieldIterator();
            }
        };
    }

    @Override
    public boolean supports(StatField field) {
        return supportsField(field);
    }

    private static boolean supportsField(StatField field) {
        switch (field.id) {
            case BYTE_COUNT:
            case DURATION:
            case FLOW_COUNT:
            case IDLE_TIME:
            case PACKET_COUNT:
                return true;
            default:
                return false;
        }
    }

    private class StatFieldIterator extends AbstractIterator> {
        private Iterator> oxsIterator;

        StatFieldIterator() {
            oxsIterator = oxsFields.iterator();
        }

        @Override
        protected StatField computeNext() {
            while(oxsIterator.hasNext()) {
                OFOxs oxs = oxsIterator.next();
                return oxs.getStatField();
            }
            endOfData();
            return null;
        }
    }

    public OFStatV6.Builder createBuilder() {
        return new BuilderWithParent(this);
    }

    static class BuilderWithParent implements OFStatV6.Builder {
        final OFStatV6Ver15 parentMessage;

        // OF message fields
        private boolean oxsFieldsSet;
        private OFOxsList oxsFields;

        BuilderWithParent(OFStatV6Ver15 parentMessage) {
            this.parentMessage = parentMessage;
        }

    @Override
    public OFOxsList getOxsFields() {
        return oxsFields;
    }

    @Override
    public OFStatV6.Builder setOxsFields(OFOxsList oxsFields) {
        this.oxsFields = oxsFields;
        this.oxsFieldsSet = true;
        return this;
    }
    @Override
    public OFVersion getVersion() {
        return OFVersion.OF_15;
    }



        @Override
        public OFStatV6 build() {
                OFOxsList oxsFields = this.oxsFieldsSet ? this.oxsFields : parentMessage.oxsFields;
                if(oxsFields == null)
                    throw new NullPointerException("Property oxsFields must not be null");

                //
                return new OFStatV6Ver15(
                    oxsFields
                );
        }
    private OFOxsList.Builder oxsFieldsBuilder;

    private void initBuilder() {
        if (oxsFieldsBuilder != null)
            return;
        oxsFieldsBuilder = new OFOxsList.Builder();
    }

    private void updateOxsList() {
        this.oxsFields = this.oxsFieldsBuilder.build();
        this.oxsFieldsSet = true;
    }



    @Override
    public > F get(StatField field) throws UnsupportedOperationException{
        if (!supports(field))
            throw new UnsupportedOperationException("OFStatV6Ver15 does not support statistics on field " + field.getName());

        OFOxs oxs = getOxs(field);

        if (oxs == null)
            return null;

        return oxs.getValue();
    }

    @Override
    public > Stat.Builder set(StatField field, F value) {
        initBuilder();
        OFOxs oxs = OFFactories.getFactory(OFVersion.OF_15).oxss().fromValue(value, field);
        this.oxsFieldsBuilder.set(oxs);
        updateOxsList();
        return this;
    }


    @Override
    public boolean supports(StatField field){
        return supportsField(field);
    }

    private > OFOxs getOxs(StatField field) {
        return this.oxsFieldsSet ? this.oxsFields.get(field) : null;
    }

    }

    static class Builder implements OFStatV6.Builder {
        // OF message fields
        private boolean oxsFieldsSet;
        private OFOxsList oxsFields;

    @Override
    public OFOxsList getOxsFields() {
        return oxsFields;
    }

    @Override
    public OFStatV6.Builder setOxsFields(OFOxsList oxsFields) {
        this.oxsFields = oxsFields;
        this.oxsFieldsSet = true;
        return this;
    }
    @Override
    public OFVersion getVersion() {
        return OFVersion.OF_15;
    }

//
        @Override
        public OFStatV6 build() {
            OFOxsList oxsFields = this.oxsFieldsSet ? this.oxsFields : DEFAULT_OXS_FIELDS;
            if(oxsFields == null)
                throw new NullPointerException("Property oxsFields must not be null");


            return new OFStatV6Ver15(
                    oxsFields
                );
        }
    private OFOxsList.Builder oxsFieldsBuilder;

    private void initBuilder() {
        if (oxsFieldsBuilder != null)
            return;
        oxsFieldsBuilder = new OFOxsList.Builder();
    }

    private void updateOxsList() {
        this.oxsFields = this.oxsFieldsBuilder.build();
        this.oxsFieldsSet = true;
    }



    @Override
    public > F get(StatField field) throws UnsupportedOperationException{
        if (!supports(field))
            throw new UnsupportedOperationException("OFStatV6Ver15 does not support statistics on field " + field.getName());

        OFOxs oxs = getOxs(field);

        if (oxs == null)
            return null;

        return oxs.getValue();
    }

    @Override
    public > Stat.Builder set(StatField field, F value) {
        initBuilder();
        OFOxs oxs = OFFactories.getFactory(OFVersion.OF_15).oxss().fromValue(value, field);
        this.oxsFieldsBuilder.set(oxs);
        updateOxsList();
        return this;
    }


    @Override
    public boolean supports(StatField field){
        return supportsField(field);
    }

    private > OFOxs getOxs(StatField field) {
        return this.oxsFieldsSet ? this.oxsFields.get(field) : null;
    }

    }


    final static Reader READER = new Reader();
    static class Reader implements OFMessageReader {
        @Override
        public OFStatV6 readFrom(ByteBuf bb) throws OFParseError {
            int start = bb.readerIndex();
            // pad: 2 bytes
            bb.skipBytes(2);
            int length = U16.f(bb.readShort());
            if(length < MINIMUM_LENGTH)
                throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
            if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
                // Buffer does not have all data yet
                bb.readerIndex(start);
                return null;
            }
            if(logger.isTraceEnabled())
                logger.trace("readFrom - length={}", length);
            OFOxsList oxsFields = OFOxsList.readFrom(bb, length - (bb.readerIndex() - start), OFOxsVer15.READER);
            // align message to 8 bytes (length does not contain alignment)
            bb.skipBytes(((length + 7)/8 * 8 ) - length );

            OFStatV6Ver15 statV6Ver15 = new OFStatV6Ver15(
                    oxsFields
                    );
            if(logger.isTraceEnabled())
                logger.trace("readFrom - read={}", statV6Ver15);
            return statV6Ver15;
        }
    }

    public void putTo(PrimitiveSink sink) {
        FUNNEL.funnel(this, sink);
    }

    final static OFStatV6Ver15Funnel FUNNEL = new OFStatV6Ver15Funnel();
    static class OFStatV6Ver15Funnel implements Funnel {
        private static final long serialVersionUID = 1L;
        @Override
        public void funnel(OFStatV6Ver15 message, PrimitiveSink sink) {
            // skip pad (2 bytes)
            // FIXME: skip funnel of length
            message.oxsFields.putTo(sink);
        }
    }


    public void writeTo(ByteBuf bb) {
        WRITER.write(bb, this);
    }

    final static Writer WRITER = new Writer();
    static class Writer implements OFMessageWriter {
        @Override
        public void write(ByteBuf bb, OFStatV6Ver15 message) {
            int startIndex = bb.writerIndex();
            // pad: 2 bytes
            bb.writeZero(2);
            // length is length of variable message, will be updated at the end
            int lengthIndex = bb.writerIndex();
            bb.writeShort(U16.t(0));

            message.oxsFields.writeTo(bb);

            // update length field
            int length = bb.writerIndex() - startIndex;
            int alignedLength = ((length + 7)/8 * 8);
            if (length > MAXIMUM_LENGTH) {
                throw new IllegalArgumentException("OFStatV6Ver15: message length (" + length + ") exceeds maximum (0xFFFF)");
            }
            bb.setShort(lengthIndex, length);
            // align message to 8 bytes
            bb.writeZero(alignedLength - length);

        }
    }

    @Override
    public String toString() {
        StringBuilder b = new StringBuilder("OFStatV6Ver15(");
        b.append("oxsFields=").append(oxsFields);
        b.append(")");
        return b.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        OFStatV6Ver15 other = (OFStatV6Ver15) obj;

        if (oxsFields == null) {
            if (other.oxsFields != null)
                return false;
        } else if (!oxsFields.equals(other.oxsFields))
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;

        result = prime * result + ((oxsFields == null) ? 0 : oxsFields.hashCode());
        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy