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

org.projectfloodlight.openflow.protocol.ver12.OFPortFeaturesSerializerVer12 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 const_set_serializer.java
// Do not modify

package org.projectfloodlight.openflow.protocol.ver12;

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.projectfloodlight.openflow.protocol.OFPortFeatures;
import java.util.Set;
import io.netty.buffer.ByteBuf;
import com.google.common.hash.PrimitiveSink;
import java.util.EnumSet;
import java.util.Collections;


public class OFPortFeaturesSerializerVer12 {

    public final static int PF_10MB_HD_VAL = 0x1;
    public final static int PF_10MB_FD_VAL = 0x2;
    public final static int PF_100MB_HD_VAL = 0x4;
    public final static int PF_100MB_FD_VAL = 0x8;
    public final static int PF_1GB_HD_VAL = 0x10;
    public final static int PF_1GB_FD_VAL = 0x20;
    public final static int PF_10GB_FD_VAL = 0x40;
    public final static int PF_COPPER_VAL = 0x800;
    public final static int PF_FIBER_VAL = 0x1000;
    public final static int PF_AUTONEG_VAL = 0x2000;
    public final static int PF_PAUSE_VAL = 0x4000;
    public final static int PF_PAUSE_ASYM_VAL = 0x8000;
    public final static int PF_40GB_FD_VAL = 0x80;
    public final static int PF_100GB_FD_VAL = 0x100;
    public final static int PF_1TB_FD_VAL = 0x200;
    public final static int PF_OTHER_VAL = 0x400;

    public static Set readFrom(ByteBuf bb) throws OFParseError {
        try {
            return ofWireValue(bb.readInt());
        } catch (IllegalArgumentException e) {
            throw new OFParseError(e);
        }
    }

    public static void writeTo(ByteBuf bb, Set set) {
        bb.writeInt(toWireValue(set));
    }

    public static void putTo(Set set, PrimitiveSink sink) {
        sink.putInt(toWireValue(set));
    }


    public static Set ofWireValue(int val) {
        EnumSet set = EnumSet.noneOf(OFPortFeatures.class);

        if((val & PF_10MB_HD_VAL) != 0)
            set.add(OFPortFeatures.PF_10MB_HD);
        if((val & PF_10MB_FD_VAL) != 0)
            set.add(OFPortFeatures.PF_10MB_FD);
        if((val & PF_100MB_HD_VAL) != 0)
            set.add(OFPortFeatures.PF_100MB_HD);
        if((val & PF_100MB_FD_VAL) != 0)
            set.add(OFPortFeatures.PF_100MB_FD);
        if((val & PF_1GB_HD_VAL) != 0)
            set.add(OFPortFeatures.PF_1GB_HD);
        if((val & PF_1GB_FD_VAL) != 0)
            set.add(OFPortFeatures.PF_1GB_FD);
        if((val & PF_10GB_FD_VAL) != 0)
            set.add(OFPortFeatures.PF_10GB_FD);
        if((val & PF_COPPER_VAL) != 0)
            set.add(OFPortFeatures.PF_COPPER);
        if((val & PF_FIBER_VAL) != 0)
            set.add(OFPortFeatures.PF_FIBER);
        if((val & PF_AUTONEG_VAL) != 0)
            set.add(OFPortFeatures.PF_AUTONEG);
        if((val & PF_PAUSE_VAL) != 0)
            set.add(OFPortFeatures.PF_PAUSE);
        if((val & PF_PAUSE_ASYM_VAL) != 0)
            set.add(OFPortFeatures.PF_PAUSE_ASYM);
        if((val & PF_40GB_FD_VAL) != 0)
            set.add(OFPortFeatures.PF_40GB_FD);
        if((val & PF_100GB_FD_VAL) != 0)
            set.add(OFPortFeatures.PF_100GB_FD);
        if((val & PF_1TB_FD_VAL) != 0)
            set.add(OFPortFeatures.PF_1TB_FD);
        if((val & PF_OTHER_VAL) != 0)
            set.add(OFPortFeatures.PF_OTHER);
        return Collections.unmodifiableSet(set);
    }

    public static int toWireValue(Set set) {
        int wireValue = 0;

        for(OFPortFeatures e: set) {
            switch(e) {
                case PF_10MB_HD:
                    wireValue |= PF_10MB_HD_VAL;
                    break;
                case PF_10MB_FD:
                    wireValue |= PF_10MB_FD_VAL;
                    break;
                case PF_100MB_HD:
                    wireValue |= PF_100MB_HD_VAL;
                    break;
                case PF_100MB_FD:
                    wireValue |= PF_100MB_FD_VAL;
                    break;
                case PF_1GB_HD:
                    wireValue |= PF_1GB_HD_VAL;
                    break;
                case PF_1GB_FD:
                    wireValue |= PF_1GB_FD_VAL;
                    break;
                case PF_10GB_FD:
                    wireValue |= PF_10GB_FD_VAL;
                    break;
                case PF_COPPER:
                    wireValue |= PF_COPPER_VAL;
                    break;
                case PF_FIBER:
                    wireValue |= PF_FIBER_VAL;
                    break;
                case PF_AUTONEG:
                    wireValue |= PF_AUTONEG_VAL;
                    break;
                case PF_PAUSE:
                    wireValue |= PF_PAUSE_VAL;
                    break;
                case PF_PAUSE_ASYM:
                    wireValue |= PF_PAUSE_ASYM_VAL;
                    break;
                case PF_40GB_FD:
                    wireValue |= PF_40GB_FD_VAL;
                    break;
                case PF_100GB_FD:
                    wireValue |= PF_100GB_FD_VAL;
                    break;
                case PF_1TB_FD:
                    wireValue |= PF_1TB_FD_VAL;
                    break;
                case PF_OTHER:
                    wireValue |= PF_OTHER_VAL;
                    break;
                default:
                    throw new IllegalArgumentException("Illegal enum value for type OFPortFeatures in version 1.2: " + e);
            }
        }
        return wireValue;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy