当前位置: 首页>>代码示例>>Java>>正文


Java PIMHello类代码示例

本文整理汇总了Java中org.onlab.packet.pim.PIMHello的典型用法代码示例。如果您正苦于以下问题:Java PIMHello类的具体用法?Java PIMHello怎么用?Java PIMHello使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PIMHello类属于org.onlab.packet.pim包,在下文中一共展示了PIMHello类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.onlab.packet.pim.PIMHello; //导入依赖的package包/类
/**
 * Create PIM Hello and Join/Prune packets to be used in testing.
 *
 * @throws Exception if packet creation fails
 */
@Before
public void setUp() throws Exception {

    // Create a PIM Hello
    pimHello = new PIM();
    pimHello.setVersion((byte) 2);
    pimHello.setPIMType((byte) PIM.TYPE_HELLO);
    pimHello.setChecksum((short) 0);

    hello = new PIMHello();
    hello.createDefaultOptions();
    pimHello.setPayload(hello);
    hello.setParent(pimHello);

    // Create PIM Join Prune
    pimJoinPrune = new PIM();
    pimJoinPrune.setVersion((byte) 2);
    pimJoinPrune.setPIMType((byte) PIM.TYPE_JOIN_PRUNE_REQUEST);
    pimJoinPrune.setChecksum((short) 0);

    joinPrune = new PIMJoinPrune();
    joinPrune.setUpstreamAddr(new PIMAddrUnicast(SADDR));
    joinPrune.addJoin(GADDR1, SADDR1);
    joinPrune.addJoin(GADDR2, SADDR2);
    joinPrune.addPrune(GADDR1, SADDR2);
    joinPrune.addPrune(GADDR2, SADDR1);

    pimJoinPrune.setPayload(joinPrune);
    joinPrune.setParent(pimJoinPrune);

    deserializer = PIM.deserializer();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:38,代码来源:PIMTest.java

示例2: sendHello

import org.onlab.packet.pim.PIMHello; //导入依赖的package包/类
/**
 * Multicast a hello message out our interface.  This hello message is sent
 * periodically during the normal PIM Neighbor refresh time, as well as a
 * result of a newly created interface.
 */
public void sendHello() {
    if (lastHello + TimeUnit.SECONDS.toMillis(helloInterval) >
            System.currentTimeMillis()) {
        return;
    }

    lastHello = System.currentTimeMillis();

    // Create the base PIM Packet and mark it a hello packet
    PimPacket pimPacket = new PimPacket(PIM.TYPE_HELLO);

    // We need to set the source MAC and IPv4 addresses
    pimPacket.setSrcMacAddr(onosInterface.mac());
    pimPacket.setSrcIpAddress(Ip4Address.valueOf(getIpAddress().toOctets()));

    // Create the hello message with options
    PIMHello hello = new PIMHello();
    hello.createDefaultOptions();
    hello.addOption(PIMHelloOption.createHoldTime(holdtime));
    hello.addOption(PIMHelloOption.createPriority(priority));
    hello.addOption(PIMHelloOption.createGenID(generationId));

    // Now set the hello option payload
    pimPacket.setPimPayload(hello);

    packetService.emit(new DefaultOutboundPacket(
            onosInterface.connectPoint().deviceId(),
            outputTreatment,
            ByteBuffer.wrap(pimPacket.getEthernet().serialize())));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:PimInterface.java

示例3: processHello

import org.onlab.packet.pim.PIMHello; //导入依赖的package包/类
/**
 * Process an incoming PIM Hello message.  There are a few things going on in
 * this method:
 * <ul>
 *     <li>We <em>may</em> have to create a new neighbor if one does not already exist</li>
 *     <li>We <em>may</em> need to re-elect a new DR if new information is received</li>
 *     <li>We <em>may</em> need to send an existing neighbor all joins if the genid changed</li>
 *     <li>We will refresh the neighbor's timestamp</li>
 * </ul>
 *
 * @param ethPkt the Ethernet packet header
 */
public void processHello(Ethernet ethPkt) {
    if (log.isTraceEnabled()) {
        log.trace("Received a PIM hello packet");
    }

    // We'll need to save our neighbors MAC address
    MacAddress nbrmac = ethPkt.getSourceMAC();

    // And we'll need to save neighbors IP Address.
    IPv4 iphdr = (IPv4) ethPkt.getPayload();
    IpAddress srcip = IpAddress.valueOf(iphdr.getSourceAddress());

    PIM pimhdr = (PIM) iphdr.getPayload();
    if (pimhdr.getPimMsgType() != PIM.TYPE_HELLO) {
        log.error("process Hello has received a non hello packet type: " + pimhdr.getPimMsgType());
        return;
    }

    // get the DR values for later calculation
    PimNeighbor dr = pimNeighbors.get(drIpaddress);
    checkNotNull(dr);

    IpAddress drip = drIpaddress;
    int drpri = dr.priority();

    // Assume we do not need to run a DR election
    boolean reElectDr = false;
    boolean genidChanged = false;

    PIMHello hello = (PIMHello) pimhdr.getPayload();

    // Determine if we already have a PIMNeighbor
    PimNeighbor nbr = pimNeighbors.getOrDefault(srcip, null);
    PimNeighbor newNbr = PimNeighbor.createPimNeighbor(srcip, nbrmac, hello.getOptions().values());

    if (nbr == null) {
        pimNeighbors.putIfAbsent(srcip, newNbr);
        nbr = newNbr;
    } else if (!nbr.equals(newNbr)) {
        if (newNbr.holdtime() == 0) {
            // Neighbor has shut down. Remove them and clean up
            pimNeighbors.remove(srcip, nbr);
            return;
        } else {
            // Neighbor has changed one of their options.
            pimNeighbors.put(srcip, newNbr);
            nbr = newNbr;
        }
    }

    // Refresh this neighbor's timestamp
    nbr.refreshTimestamp();

    /*
     * the election method will first determine if an election
     * needs to be run, if so it will run the election.  The
     * IP address of the DR will be returned.  If the IP address
     * of the DR is different from what we already have we know a
     * new DR has been elected.
     */
    IpAddress electedIp = election(nbr, drip, drpri);
    if (!drip.equals(electedIp)) {
        // we have a new DR.
        drIpaddress = electedIp;
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:79,代码来源:PimInterface.java


注:本文中的org.onlab.packet.pim.PIMHello类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。