Search in sources :

Example 1 with PIMHello

use of org.onlab.packet.pim.PIMHello in project onos by opennetworkinglab.

the class PimInterface method processHello.

/**
 * 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;
    }
}
Also used : PIM(org.onlab.packet.PIM) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) MacAddress(org.onlab.packet.MacAddress) PIMHello(org.onlab.packet.pim.PIMHello)

Example 2 with PIMHello

use of org.onlab.packet.pim.PIMHello in project onos by opennetworkinglab.

the class PIMTest method setUp.

/**
 * 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();
}
Also used : PIMJoinPrune(org.onlab.packet.pim.PIMJoinPrune) PIMAddrUnicast(org.onlab.packet.pim.PIMAddrUnicast) PIMHello(org.onlab.packet.pim.PIMHello) Before(org.junit.Before)

Example 3 with PIMHello

use of org.onlab.packet.pim.PIMHello in project onos by opennetworkinglab.

the class PimInterface method sendHello.

/**
 * 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())));
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PIMHello(org.onlab.packet.pim.PIMHello)

Aggregations

PIMHello (org.onlab.packet.pim.PIMHello)3 Before (org.junit.Before)1 IPv4 (org.onlab.packet.IPv4)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 PIM (org.onlab.packet.PIM)1 PIMAddrUnicast (org.onlab.packet.pim.PIMAddrUnicast)1 PIMJoinPrune (org.onlab.packet.pim.PIMJoinPrune)1 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)1 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)1