Search in sources :

Example 1 with GetMacOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacOutput 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());
}
Also used : InterfaceAddressBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddressBuilder) InterfaceAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetMacInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInput) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) GetMacInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInputBuilder) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) Test(org.junit.Test)

Example 2 with GetMacOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacOutput 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());
    }
}
Also used : RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) UnknownHostException(java.net.UnknownHostException) SendArpRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetMacOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacOutput)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 UnknownHostException (java.net.UnknownHostException)1 Test (org.junit.Test)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)1 GetMacInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInput)1 GetMacInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacInputBuilder)1 GetMacOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.GetMacOutput)1 SendArpRequestInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInputBuilder)1 InterfaceAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress)1 InterfaceAddressBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddressBuilder)1 PacketReceived (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived)1 RpcResultBuilder (org.opendaylight.yangtools.yang.common.RpcResultBuilder)1