use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInput in project genius by opendaylight.
the class ArpUtilTest method testGetMac.
@Test
public void testGetMac() throws Exception {
final InterfaceAddress interfaceAddress = new InterfaceAddressBuilder().setInterface(INTERFACE_NAME).setIpAddress(new IpAddress(Ipv4Address.getDefaultInstance("192.168.0.1"))).setMacaddress(new PhysAddress("1F:1F:1F:1F:1F:1F")).build();
final List<InterfaceAddress> itf = Arrays.asList(interfaceAddress);
GetMacInput getMacInput = new GetMacInputBuilder().setIpaddress(new IpAddress(Ipv4Address.getDefaultInstance("192.168.0.2"))).setInterfaceAddress(itf).build();
// request payload
PacketReceived packetReceived = ArpUtilTestUtil.createPayload(0);
Future<RpcResult<GetMacOutput>> output = odlArputilService.getMac(getMacInput);
arpUtil.onPacketReceived(packetReceived);
Assert.assertEquals("00:01:02:03:04:05", output.get().getResult().getMacaddress().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInput in project genius by opendaylight.
the class ArpUtilImpl method getMac.
@Override
public Future<RpcResult<GetMacOutput>> getMac(GetMacInput input) {
try {
final String dstIpAddress = getIpAddressInString(input.getIpaddress());
LOG.trace("getMac rpc invoked for ip {}", dstIpAddress);
if (macAddrs.get(dstIpAddress) != null) {
if (LOG.isInfoEnabled()) {
LOG.info("get mac already in progress for the ip {}", dstIpAddress);
}
return macAddrs.get(dstIpAddress);
}
SendArpRequestInputBuilder builder = new SendArpRequestInputBuilder().setInterfaceAddress(input.getInterfaceAddress()).setIpaddress(input.getIpaddress());
Future<RpcResult<Void>> arpReqFt = sendArpRequest(builder.build());
final SettableFuture<RpcResult<GetMacOutput>> ft = SettableFuture.create();
Futures.addCallback(JdkFutureAdapters.listenInPoolThread(arpReqFt, threadPool), new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(Throwable ex) {
RpcResultBuilder<GetMacOutput> resultBuilder = RpcResultBuilder.<GetMacOutput>failed().withError(ErrorType.APPLICATION, ex.getMessage(), ex);
ft.set(resultBuilder.build());
}
@Override
public void onSuccess(RpcResult<Void> result) {
LOG.trace("Successfully sent the arp pkt out for ip {}", dstIpAddress);
}
}, MoreExecutors.directExecutor());
macAddrs.put(dstIpAddress, ft);
return ft;
} catch (UnknownHostException e) {
LOG.error("Failed to handle getMac request for {}", input.getIpaddress(), e);
RpcResultBuilder<GetMacOutput> resultBuilder = RpcResultBuilder.<GetMacOutput>failed().withError(ErrorType.APPLICATION, e.getMessage(), e);
return Futures.immediateFuture(resultBuilder.build());
}
}
Aggregations