java实现数字转mac,Java Ethernet.getSourceMAC方法代码示例

import org.onlab.packet.Ethernet; //导入方法依赖的package包/类

/**

* Process an incoming PIM Hello message. There are a few things going on in

* this method:

*

*

We may have to create a new neighbor if one does not already exist

*

We may need to re-elect a new DR if new information is received

*

We may need to send an existing neighbor all joins if the genid changed

*

We will refresh the neighbor's timestamp

*

*

* @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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值