本文整理匯總了Java中org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket類的典型用法代碼示例。如果您正苦於以下問題:Java LsRequestPacket類的具體用法?Java LsRequestPacket怎麽用?Java LsRequestPacket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LsRequestPacket類屬於org.onosproject.ospf.protocol.ospfpacket.subtype包,在下文中一共展示了LsRequestPacket類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readFrom
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
@Override
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
while (channelBuffer.readableBytes() >= OspfUtil.LSREQUEST_LENGTH) {
LsRequestPacket lsRequestPacket = new LsRequestPacket();
lsRequestPacket.setLsType(channelBuffer.readInt());
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
lsRequestPacket.setLinkStateId(Ip4Address.valueOf(tempByteArray).toString());
tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
lsRequestPacket.setOwnRouterId(Ip4Address.valueOf(tempByteArray).toString());
this.addLinkStateRequests(lsRequestPacket);
}
}
示例2: getLsrBodyAsByteArray
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Gets LS request packet body as byte array.
*
* @return LS request packet body as byte array
*/
public byte[] getLsrBodyAsByteArray() {
List<Byte> bodyLst = new ArrayList<>();
try {
for (LsRequestPacket lsrPacket : linkStateRequests) {
bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(lsrPacket.lsType())));
bodyLst.addAll(Bytes.asList(InetAddress.getByName(lsrPacket.linkStateId()).getAddress()));
bodyLst.addAll(Bytes.asList(InetAddress.getByName(lsrPacket.ownRouterId()).getAddress()));
}
} catch (Exception e) {
log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
return Bytes.toArray(bodyLst);
}
return Bytes.toArray(bodyLst);
}
示例3: testGetLinkStateRequests
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Tests getLinkStateRequests() method.
*/
@Test
public void testGetLinkStateRequests() throws Exception {
lsRequest.addLinkStateRequests(createLsRequestPacket());
lsRequest.addLinkStateRequests(new LsRequestPacket());
result = lsRequest.getLinkStateRequests();
assertThat(result, is(notNullValue()));
assertThat(result.size(), is(2));
}
示例4: testGetLsrBodyAsByteArray
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Tests getLsrBodyAsByteArray() method.
*/
@Test
public void testGetLsrBodyAsByteArray() throws Exception {
lsRequest.addLinkStateRequests(createLsRequestPacket());
lsRequest.addLinkStateRequests(new LsRequestPacket());
result1 = lsRequest.getLsrBodyAsByteArray();
assertThat(result1, is(notNullValue()));
}
示例5: createLsRequestPacket
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
private LsRequestPacket createLsRequestPacket() throws UnknownHostException {
lsRequestPacket = new LsRequestPacket();
lsRequestPacket.setOwnRouterId("165");
lsRequestPacket.setLinkStateId("10.226.165.164");
lsRequestPacket.setLsType(2);
return lsRequestPacket;
}
示例6: addLinkStateRequests
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Adds link state request.
*
* @param lsRequestPacket ls request packet instance
*/
public void addLinkStateRequests(LsRequestPacket lsRequestPacket) {
if (!linkStateRequests.contains(lsRequestPacket)) {
linkStateRequests.add(lsRequestPacket);
}
}
示例7: processLsRequestMessage
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Process the Ls Request message.
*
* @param ospfMessage OSPF message instance.
* @param ctx channel handler context instance.
* @throws Exception might throws exception
*/
void processLsRequestMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
log.debug("OspfChannelHandler::processLsRequestMessage...!!!");
Channel channel = ctx.getChannel();
LsRequest lsrPacket = (LsRequest) ospfMessage;
OspfNbr nbr = neighbouringRouter(lsrPacket.routerId().toString());
if (nbr.getState() == OspfNeighborState.EXCHANGE || nbr.getState() == OspfNeighborState.LOADING ||
nbr.getState() == OspfNeighborState.FULL) {
LsRequest reqMsg = (LsRequest) ospfMessage;
if (reqMsg.getLinkStateRequests().isEmpty()) {
log.debug("Received Link State Request Vector is Empty ");
return;
} else {
//Send the LsUpdate back
ListIterator<LsRequestPacket> listItr = reqMsg.getLinkStateRequests().listIterator();
while (listItr.hasNext()) {
LsUpdate lsupdate = new LsUpdate();
lsupdate.setOspfVer(OspfUtil.OSPF_VERSION);
lsupdate.setOspftype(OspfPacketType.LSUPDATE.value());
lsupdate.setRouterId(ospfArea.routerId());
lsupdate.setAreaId(ospfArea.areaId());
lsupdate.setAuthType(OspfUtil.NOT_ASSIGNED);
lsupdate.setAuthentication(OspfUtil.NOT_ASSIGNED);
lsupdate.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
lsupdate.setChecksum(OspfUtil.NOT_ASSIGNED);
//limit to mtu
int currentLength = OspfUtil.OSPF_HEADER_LENGTH + OspfUtil.FOUR_BYTES;
int maxSize = mtu() -
OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
int noLsa = 0;
while (listItr.hasNext()) {
LsRequestPacket lsRequest = (LsRequestPacket) listItr.next();
// to verify length of the LSA
LsaWrapper wrapper = ospfArea.getLsa(lsRequest.lsType(), lsRequest.linkStateId(),
lsRequest.ownRouterId());
OspfLsa ospflsa = wrapper.ospfLsa();
if ((currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen()) >= maxSize) {
listItr.previous();
break;
}
if (ospflsa != null) {
lsupdate.addLsa(ospflsa);
noLsa++;
currentLength = currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen();
} else {
nbr.badLSReq(channel);
}
}
lsupdate.setNumberOfLsa(noLsa);
//set the destination
if (state() == OspfInterfaceState.DR ||
state() == OspfInterfaceState.BDR ||
state() == OspfInterfaceState.POINT2POINT) {
lsupdate.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
} else if (state() == OspfInterfaceState.DROTHER) {
lsupdate.setDestinationIp(OspfUtil.ALL_DROUTERS);
}
byte[] messageToWrite = getMessage(lsupdate);
ctx.getChannel().write(messageToWrite);
}
}
}
}
示例8: buildLsRequest
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Builds LS Request.
*
* @return ls request instance
*/
private LsRequest buildLsRequest() {
//send link state request packet to neighbor
//for recent lsa's which are not received in exchange state
LsRequest lsRequest = new LsRequest();
lsRequest.setOspfVer(OspfUtil.OSPF_VERSION);
lsRequest.setOspftype(OspfPacketType.LSREQUEST.value());
lsRequest.setRouterId(ospfArea.routerId());
lsRequest.setAreaId(ospfArea.areaId());
lsRequest.setAuthType(OspfUtil.NOT_ASSIGNED);
lsRequest.setAuthentication(OspfUtil.NOT_ASSIGNED);
lsRequest.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
lsRequest.setChecksum(OspfUtil.NOT_ASSIGNED);
Set lsaKeys = lsReqList.keySet();
Iterator itr = lsaKeys.iterator();
int currentLength = OspfUtil.OSPF_HEADER_LENGTH;
int maxSize = ospfInterface.mtu() -
OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
while (itr.hasNext()) {
if ((currentLength + OspfUtil.LSREQUEST_LENGTH) >= maxSize) {
break;
}
LsRequestPacket lsRequestPacket = new LsRequestPacket();
String key = ((String) itr.next());
String[] lsaKey = key.split("-");
OspfLsa lsa = (OspfLsa) lsReqList.get(key);
lsRequestPacket.setLsType(Integer.valueOf(lsaKey[0]));
lsRequestPacket.setOwnRouterId(lsaKey[2]);
if (((lsa.getOspfLsaType().value() == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) ||
(lsa.getOspfLsaType().value() == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value())) ||
(lsa.getOspfLsaType().value() == OspfLsaType.AS_OPAQUE_LSA.value())) {
OpaqueLsaHeader header = (OpaqueLsaHeader) lsa;
byte[] opaqueIdBytes = OspfUtil.convertToTwoBytes(header.opaqueId());
lsRequestPacket.setLinkStateId(header.opaqueType() + "." + "0" + "." + opaqueIdBytes[0]
+ "." + opaqueIdBytes[1]);
} else {
lsRequestPacket.setLinkStateId(lsaKey[1]);
}
lsRequest.addLinkStateRequests(lsRequestPacket);
currentLength = currentLength + OspfUtil.LSREQUEST_LENGTH;
}
return lsRequest;
}
示例9: processLsRequestMessage
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Process the Ls Request message.
*
* @param ospfMessage OSPF message instance.
* @param ctx channel handler context instance.
*/
void processLsRequestMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) {
log.debug("OspfChannelHandler::processLsRequestMessage...!!!");
Channel channel = ctx.getChannel();
LsRequest lsrPacket = (LsRequest) ospfMessage;
OspfNbr nbr = neighbouringRouter(lsrPacket.routerId().toString());
if (nbr.getState() == OspfNeighborState.EXCHANGE || nbr.getState() == OspfNeighborState.LOADING ||
nbr.getState() == OspfNeighborState.FULL) {
LsRequest reqMsg = (LsRequest) ospfMessage;
if (reqMsg.getLinkStateRequests().isEmpty()) {
log.debug("Received Link State Request Vector is Empty ");
return;
} else {
//Send the LsUpdate back
ListIterator<LsRequestPacket> listItr = reqMsg.getLinkStateRequests().listIterator();
while (listItr.hasNext()) {
LsUpdate lsupdate = new LsUpdate();
lsupdate.setOspfVer(OspfUtil.OSPF_VERSION);
lsupdate.setOspftype(OspfPacketType.LSUPDATE.value());
lsupdate.setRouterId(ospfArea.routerId());
lsupdate.setAreaId(ospfArea.areaId());
lsupdate.setAuthType(OspfUtil.NOT_ASSIGNED);
lsupdate.setAuthentication(OspfUtil.NOT_ASSIGNED);
lsupdate.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
lsupdate.setChecksum(OspfUtil.NOT_ASSIGNED);
//limit to mtu
int currentLength = OspfUtil.OSPF_HEADER_LENGTH + OspfUtil.FOUR_BYTES;
int maxSize = mtu() -
OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
int noLsa = 0;
while (listItr.hasNext()) {
LsRequestPacket lsRequest = listItr.next();
// to verify length of the LSA
LsaWrapper wrapper = ospfArea.getLsa(lsRequest.lsType(), lsRequest.linkStateId(),
lsRequest.ownRouterId());
if (wrapper != null) {
OspfLsa ospflsa = wrapper.ospfLsa();
if ((currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen()) >= maxSize) {
listItr.previous();
break;
}
if (ospflsa != null) {
lsupdate.addLsa(ospflsa);
noLsa++;
currentLength = currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen();
} else {
nbr.badLSReq(channel);
}
}
}
lsupdate.setNumberOfLsa(noLsa);
//set the destination
if (state() == OspfInterfaceState.DR ||
state() == OspfInterfaceState.BDR ||
state() == OspfInterfaceState.POINT2POINT) {
lsupdate.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
} else if (state() == OspfInterfaceState.DROTHER) {
lsupdate.setDestinationIp(OspfUtil.ALL_DROUTERS);
}
byte[] messageToWrite = getMessage(lsupdate);
ctx.getChannel().write(messageToWrite);
}
}
}
}
示例10: getLinkStateRequests
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; //導入依賴的package包/類
/**
* Gets link state request packet instance.
*
* @return link state request packet instance
*/
public List<LsRequestPacket> getLinkStateRequests() {
return linkStateRequests;
}