當前位置: 首頁>>代碼示例>>Java>>正文


Java Med類代碼示例

本文整理匯總了Java中org.onosproject.bgpio.types.Med的典型用法代碼示例。如果您正苦於以下問題:Java Med類的具體用法?Java Med怎麽用?Java Med使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Med類屬於org.onosproject.bgpio.types包,在下文中一共展示了Med類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: storeAttr

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * Stores BGP basic attributes of two objects.
 *
 * @param listIteratorObj1 list iterator of object1
 * @param listIteratorObj2 list iterator of object2
 */
void storeAttr(ListIterator<BgpValueType> listIteratorObj1, ListIterator<BgpValueType> listIteratorObj2) {
     while (listIteratorObj1.hasNext()) {
         BgpValueType pathAttributeObj1 = listIteratorObj1.next();
         switch (pathAttributeObj1.getType()) {
         case LocalPref.LOCAL_PREF_TYPE:
             obj1LocPref = (LocalPref) pathAttributeObj1;
             break;
         case AsPath.ASPATH_TYPE:
             obj1Aspath = (AsPath) pathAttributeObj1;
             break;
         case Origin.ORIGIN_TYPE:
             obj1Origin = (Origin) pathAttributeObj1;
             break;
         case Med.MED_TYPE:
             obj1Med = (Med) pathAttributeObj1;
             break;
         default:
             log.debug("Got other type, Not required: " + pathAttributeObj1.getType());
         }
     }
     while (listIteratorObj2.hasNext()) {
         BgpValueType pathAttributeObj2 = listIteratorObj2.next();
         switch (pathAttributeObj2.getType()) {
         case LocalPref.LOCAL_PREF_TYPE:
             obj2LocPref = (LocalPref) pathAttributeObj2;
             break;
         case AsPath.ASPATH_TYPE:
             obj2Aspath = (AsPath) pathAttributeObj2;
             break;
         case Origin.ORIGIN_TYPE:
             obj2Origin = (Origin) pathAttributeObj2;
             break;
         case Med.MED_TYPE:
             obj2Med = (Med) pathAttributeObj2;
             break;
         default:
             log.debug("Got other type, Not required: " + pathAttributeObj2.getType());
         }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:47,代碼來源:BgpSelectionAlgo.java

示例2: selectionAlgoTest4

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * firstPathAttribute has lowest med than secondPathAttribute.
 */
@Test
public void selectionAlgoTest4() throws BgpParseException {

    byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
    LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
    BgpValueType pathAttribute1;
    byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute1 = Origin.read(buffer);
    pathAttributes1.add(pathAttribute1);
    byte[] med = new byte[] {(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00,
            0x00 };
    buffer.writeBytes(med);
    pathAttribute1 = Med.read(buffer);
    pathAttributes1.add(pathAttribute1);
    byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
            (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute1 = AsPath.read(buffer);
    pathAttributes1.add(pathAttribute1);

    IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    int bgpId = 168427777;
    short locRibAsNum = 100;
    boolean isIbgp = false;
    PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
    attrList1.setIdentifier(0);
    attrList1.setPathAttribute(pathAttributes1);
    attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
    PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
            ipAddress, bgpId, locRibAsNum, isIbgp, attrList1);

    peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
    LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
    BgpValueType pathAttribute2;
    origin = new byte[] {0x40, 0x01, 0x01, 0x02 };
    buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute2 = Origin.read(buffer);
    pathAttributes2.add(pathAttribute2);
    med = new byte[] {(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x01 };
    buffer.writeBytes(med);
    pathAttribute2 = Med.read(buffer);
    pathAttributes2.add(pathAttribute2);
    asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
            (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute2 = AsPath.read(buffer);
    pathAttributes2.add(pathAttribute2);

    ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    bgpId = 536936448;
    locRibAsNum = 200;
    isIbgp = true;
    PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
    attrList2.setIdentifier(0);
    attrList2.setPathAttribute(pathAttributes2);
    attrList2.setProtocolID(ProtocolType.OSPF_V2);
    PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
            ipAddress, bgpId, locRibAsNum, isIbgp, attrList2);
    BgpSelectionAlgo algo = new BgpSelectionAlgo();
    int result = algo.compare(list1, list2);
    assertThat(result, is(1));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:69,代碼來源:BgpSelectionAlgoTest.java

示例3: read

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * Reads from channelBuffer and parses BGP path attributes.
 *
 * @param cb channelBuffer
 * @return object of BgpPathAttributes
 * @throws BgpParseException while parsing BGP path attributes
 */
public static BgpPathAttributes read(ChannelBuffer cb)
        throws BgpParseException {

    BgpValueType pathAttribute = null;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    boolean isOrigin = false;
    boolean isAsPath = false;
    boolean isNextHop = false;
    boolean isMpReach = false;
    boolean isMpUnReach = false;
    while (cb.readableBytes() > 0) {
        cb.markReaderIndex();
        byte flags = cb.readByte();
        byte typeCode = cb.readByte();
        cb.resetReaderIndex();
        switch (typeCode) {
        case Origin.ORIGIN_TYPE:
            pathAttribute = Origin.read(cb);
            isOrigin = ((Origin) pathAttribute).isOriginSet();
            break;
        case AsPath.ASPATH_TYPE:
            pathAttribute = AsPath.read(cb);
            isAsPath = ((AsPath) pathAttribute).isaspathSet();
            break;
        case As4Path.AS4PATH_TYPE:
            pathAttribute = As4Path.read(cb);
            break;
        case NextHop.NEXTHOP_TYPE:
            pathAttribute = NextHop.read(cb);
            isNextHop = ((NextHop) pathAttribute).isNextHopSet();
            break;
        case Med.MED_TYPE:
            pathAttribute = Med.read(cb);
            break;
        case LocalPref.LOCAL_PREF_TYPE:
            pathAttribute = LocalPref.read(cb);
            break;
        case MpReachNlri.MPREACHNLRI_TYPE:
            pathAttribute = MpReachNlri.read(cb);
            isMpReach = ((MpReachNlri) pathAttribute).isMpReachNlriSet();
            break;
        case MpUnReachNlri.MPUNREACHNLRI_TYPE:
            pathAttribute = MpUnReachNlri.read(cb);
            isMpUnReach = ((MpUnReachNlri) pathAttribute)
                    .isMpUnReachNlriSet();
            break;
        case LINK_STATE_ATTRIBUTE_TYPE:
            pathAttribute = LinkStateAttributes.read(cb);
            break;
        case EXTENDED_COMMUNITY_TYPE:
            pathAttribute = BgpExtendedCommunity.read(cb);
            break;
        case WideCommunity.TYPE:
            pathAttribute = WideCommunity.read(cb);
            break;
        default:
            //skip bytes for unsupported attribute types
            UnSupportedAttribute.read(cb);
        }
        pathAttributeList.add(pathAttribute);
    }

    checkMandatoryAttr(isOrigin, isAsPath, isNextHop, isMpReach, isMpUnReach);
    //TODO:if mp_reach or mp_unreach not present ignore the packet
    return new BgpPathAttributes(pathAttributeList);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:74,代碼來源:BgpPathAttributes.java

示例4: write

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * Write path attributes to channelBuffer.
 *
 * @param cb channelBuffer
 * @return object of BgpPathAttributes
 * @throws BgpParseException while parsing BGP path attributes
 */
public int write(ChannelBuffer cb)
        throws BgpParseException {

    if (pathAttribute == null) {
        return 0;
    }
    int iLenStartIndex = cb.writerIndex();

    ListIterator<BgpValueType> iterator = pathAttribute.listIterator();

    int pathAttributeIndx = cb.writerIndex();
    cb.writeShort(0);

    while (iterator.hasNext()) {

        BgpValueType attr = iterator.next();

        switch (attr.getType()) {
        case Origin.ORIGIN_TYPE:
            Origin origin = (Origin) attr;
            origin.write(cb);
            break;
        case AsPath.ASPATH_TYPE:
            AsPath asPath = (AsPath) attr;
            asPath.write(cb);
            break;
        case As4Path.AS4PATH_TYPE:
            As4Path as4Path = (As4Path) attr;
            as4Path.write(cb);
            break;
        case NextHop.NEXTHOP_TYPE:
            NextHop nextHop = (NextHop) attr;
            nextHop.write(cb);
            break;
        case Med.MED_TYPE:
            Med med = (Med) attr;
            med.write(cb);
            break;
        case LocalPref.LOCAL_PREF_TYPE:
            LocalPref localPref = (LocalPref) attr;
            localPref.write(cb);
            break;
        case Constants.BGP_EXTENDED_COMMUNITY:
            BgpExtendedCommunity extendedCommunity = (BgpExtendedCommunity) attr;
            extendedCommunity.write(cb);
            break;
        case WideCommunity.TYPE:
            WideCommunity wideCommunity = (WideCommunity) attr;
            wideCommunity.write(cb);
            break;
        case MpReachNlri.MPREACHNLRI_TYPE:
            MpReachNlri mpReach = (MpReachNlri) attr;
            mpReach.write(cb);
            break;
        case MpUnReachNlri.MPUNREACHNLRI_TYPE:
            MpUnReachNlri mpUnReach = (MpUnReachNlri) attr;
            mpUnReach.write(cb);
            break;
        case LINK_STATE_ATTRIBUTE_TYPE:
            LinkStateAttributes linkState = (LinkStateAttributes) attr;
            linkState.write(cb);
            break;
        default:
            return cb.writerIndex() - iLenStartIndex;
        }
    }

    int pathAttrLen = cb.writerIndex() - pathAttributeIndx;
    cb.setShort(pathAttributeIndx, (short) (pathAttrLen - 2));
    return cb.writerIndex() - iLenStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:79,代碼來源:BgpPathAttributes.java

示例5: storeAttr

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * Stores BGP basic attributes of two objects.
 *
 * @param listIteratorObj1 list iterator of object1
 * @param listIteratorObj2 list iterator of object2
 */
private void storeAttr(ListIterator<BgpValueType> listIteratorObj1, ListIterator<BgpValueType> listIteratorObj2) {
     while (listIteratorObj1.hasNext()) {
         BgpValueType pathAttributeObj1 = listIteratorObj1.next();
         switch (pathAttributeObj1.getType()) {
         case LocalPref.LOCAL_PREF_TYPE:
             obj1LocPref = (LocalPref) pathAttributeObj1;
             break;
         case AsPath.ASPATH_TYPE:
             obj1Aspath = (AsPath) pathAttributeObj1;
             break;
         case Origin.ORIGIN_TYPE:
             obj1Origin = (Origin) pathAttributeObj1;
             break;
         case Med.MED_TYPE:
             obj1Med = (Med) pathAttributeObj1;
             break;
         default:
             log.debug("Got other type, Not required: " + pathAttributeObj1.getType());
         }
     }
     while (listIteratorObj2.hasNext()) {
         BgpValueType pathAttributeObj2 = listIteratorObj2.next();
         switch (pathAttributeObj2.getType()) {
         case LocalPref.LOCAL_PREF_TYPE:
             obj2LocPref = (LocalPref) pathAttributeObj2;
             break;
         case AsPath.ASPATH_TYPE:
             obj2Aspath = (AsPath) pathAttributeObj2;
             break;
         case Origin.ORIGIN_TYPE:
             obj2Origin = (Origin) pathAttributeObj2;
             break;
         case Med.MED_TYPE:
             obj2Med = (Med) pathAttributeObj2;
             break;
         default:
             log.debug("Got other type, Not required: " + pathAttributeObj2.getType());
         }
    }
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:47,代碼來源:BgpSelectionAlgo.java

示例6: read

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * Reads from channelBuffer and parses BGP path attributes.
 *
 * @param cb channelBuffer
 * @return object of BgpPathAttributes
 * @throws BgpParseException while parsing BGP path attributes
 */
public static BgpPathAttributes read(ChannelBuffer cb)
        throws BgpParseException {

    BgpValueType pathAttribute = null;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    boolean isOrigin = false;
    boolean isAsPath = false;
    boolean isNextHop = false;
    boolean isMpReach = false;
    boolean isMpUnReach = false;
    while (cb.readableBytes() > 0) {
        cb.markReaderIndex();
        byte flags = cb.readByte();
        byte typeCode = cb.readByte();
        cb.resetReaderIndex();
        switch (typeCode) {
        case Origin.ORIGIN_TYPE:
            pathAttribute = Origin.read(cb);
            isOrigin = ((Origin) pathAttribute).isOriginSet();
            break;
        case AsPath.ASPATH_TYPE:
            pathAttribute = AsPath.read(cb);
            isAsPath = ((AsPath) pathAttribute).isaspathSet();
            break;
        case As4Path.AS4PATH_TYPE:
            pathAttribute = As4Path.read(cb);
            break;
        case NextHop.NEXTHOP_TYPE:
            pathAttribute = NextHop.read(cb);
            isNextHop = ((NextHop) pathAttribute).isNextHopSet();
            break;
        case Med.MED_TYPE:
            pathAttribute = Med.read(cb);
            break;
        case LocalPref.LOCAL_PREF_TYPE:
            pathAttribute = LocalPref.read(cb);
            break;
        case MpReachNlri.MPREACHNLRI_TYPE:
            pathAttribute = MpReachNlri.read(cb);
            isMpReach = ((MpReachNlri) pathAttribute).isMpReachNlriSet();
            break;
        case MpUnReachNlri.MPUNREACHNLRI_TYPE:
            pathAttribute = MpUnReachNlri.read(cb);
            isMpUnReach = ((MpUnReachNlri) pathAttribute)
                    .isMpUnReachNlriSet();
            break;
        case LINK_STATE_ATTRIBUTE_TYPE:
            pathAttribute = LinkStateAttributes.read(cb);
            break;
        case EXTENDED_COMMUNITY_TYPE:
            pathAttribute = BgpExtendedCommunity.read(cb);
            break;
        case WideCommunity.TYPE:
            pathAttribute = WideCommunity.read(cb);
            break;
        default:
            log.debug("Skip bytes for unsupported attribute types");
            UnSupportedAttribute.read(cb);
        }
        pathAttributeList.add(pathAttribute);
    }

    checkMandatoryAttr(isOrigin, isAsPath, isNextHop, isMpReach, isMpUnReach);
    //TODO:if mp_reach or mp_unreach not present ignore the packet
    return new BgpPathAttributes(pathAttributeList);
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:74,代碼來源:BgpPathAttributes.java

示例7: compareMed

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * Compare Med of two objects and returns object with lowestMed value.
 *
 * @param obj1Med Med object1
 * @param obj2Med Med object2
 * @return returns object with lowestMed value
 */
int compareMed(Med obj1Med, Med obj2Med) {
    return ((Integer) (obj2Med.med())).compareTo((Integer) (obj1Med.med()));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:11,代碼來源:BgpSelectionAlgo.java

示例8: compareMed

import org.onosproject.bgpio.types.Med; //導入依賴的package包/類
/**
 * Compare Med of two objects and returns object with lowestMed value.
 *
 * @param obj1Med Med object1
 * @param obj2Med Med object2
 * @return returns object with lowestMed value
 */
private int compareMed(Med obj1Med, Med obj2Med) {
    return Integer.compare(obj2Med.med(), obj1Med.med());
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:11,代碼來源:BgpSelectionAlgo.java


注:本文中的org.onosproject.bgpio.types.Med類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。