use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project genius by opendaylight.
the class ArpUtilImpl method sendArpRequest.
@Override
public Future<RpcResult<Void>> sendArpRequest(SendArpRequestInput arpReqInput) {
LOG.trace("rpc sendArpRequest invoked for ip {}", arpReqInput.getIpaddress());
BigInteger dpnId;
byte[] payload;
String interfaceName = null;
byte[] srcIpBytes;
byte[] dstIpBytes;
byte[] srcMac;
RpcResultBuilder<Void> failureBuilder = RpcResultBuilder.failed();
RpcResultBuilder<Void> successBuilder = RpcResultBuilder.success();
try {
dstIpBytes = getIpAddressBytes(arpReqInput.getIpaddress());
} catch (UnknownHostException e) {
LOG.error("Cannot get IP address", e);
failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.UNKNOWN_IP_ADDRESS_SUPPLIED);
return Futures.immediateFuture(failureBuilder.build());
}
int localErrorCount = 0;
for (InterfaceAddress interfaceAddress : arpReqInput.getInterfaceAddress()) {
try {
interfaceName = interfaceAddress.getInterface();
srcIpBytes = getIpAddressBytes(interfaceAddress.getIpAddress());
GetPortFromInterfaceOutput portResult = getPortFromInterface(interfaceName);
checkNotNull(portResult);
dpnId = portResult.getDpid();
Long portid = portResult.getPortno();
checkArgument(null != dpnId && !BigInteger.ZERO.equals(dpnId), ArpConstants.DPN_NOT_FOUND_ERROR, interfaceName);
NodeConnectorRef ref = MDSALUtil.getNodeConnRef(dpnId, portid.toString());
checkNotNull(ref, ArpConstants.NODE_CONNECTOR_NOT_FOUND_ERROR, interfaceName);
LOG.trace("sendArpRequest received dpnId {} out interface {}", dpnId, interfaceName);
if (interfaceAddress.getMacaddress() == null) {
srcMac = MDSALUtil.getMacAddressForNodeConnector(dataBroker, (InstanceIdentifier<NodeConnector>) ref.getValue());
} else {
String macAddr = interfaceAddress.getMacaddress().getValue();
srcMac = HexEncode.bytesFromHexString(macAddr);
}
checkNotNull(srcMac, ArpConstants.FAILED_TO_GET_SRC_MAC_FOR_INTERFACE, interfaceName, ref.getValue());
checkNotNull(srcIpBytes, ArpConstants.FAILED_TO_GET_SRC_IP_FOR_INTERFACE, interfaceName);
payload = ArpPacketUtil.getPayload(ArpConstants.ARP_REQUEST_OP, srcMac, srcIpBytes, ArpPacketUtil.ETHERNET_BROADCAST_DESTINATION, dstIpBytes);
List<Action> actions = getEgressAction(interfaceName);
sendPacketOutWithActions(dpnId, payload, ref, actions);
LOG.trace("sent arp request for {}", arpReqInput.getIpaddress());
} catch (UnknownHostException | PacketException | InterruptedException | ExecutionException | ReadFailedException e) {
LOG.trace("failed to send arp req for {} on interface {}", arpReqInput.getIpaddress(), interfaceName);
failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
successBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
localErrorCount++;
}
}
if (localErrorCount == arpReqInput.getInterfaceAddress().size()) {
// All the requests failed
return Futures.immediateFuture(failureBuilder.build());
}
return Futures.immediateFuture(successBuilder.build());
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.
the class RpcbenchmarkProvider method startTest.
@Override
public Future<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
LOG.debug("startTest {}", input);
final RTCClient client;
final List<RoutedRpcRegistration<?>> rpcRegs = new ArrayList<>();
switch(input.getOperation()) {
case ROUTEDRTC:
List<InstanceIdentifier<?>> routeIid = new ArrayList<>();
for (int i = 0; i < input.getNumServers().intValue(); i++) {
GlobalBindingRTCServer server = new GlobalBindingRTCServer();
RoutedRpcRegistration<RpcbenchPayloadService> routedReg = providerRegistry.addRoutedRpcImplementation(RpcbenchPayloadService.class, server);
KeyedInstanceIdentifier<RpcRoute, RpcRouteKey> iid = InstanceIdentifier.create(RpcbenchRpcRoutes.class).child(RpcRoute.class, new RpcRouteKey(Integer.toString(i)));
routeIid.add(iid);
routedReg.registerPath(NodeContext.class, iid);
rpcRegs.add(routedReg);
}
client = new RoutedBindingRTClient(providerRegistry, input.getPayloadSize().intValue(), routeIid);
break;
case GLOBALRTC:
client = new GlobalBindingRTCClient(providerRegistry, input.getPayloadSize().intValue());
break;
default:
LOG.error("Unsupported server/client type {}", input.getOperation());
throw new IllegalArgumentException("Unsupported server/client type" + input.getOperation());
}
try {
ExecutorService executor = Executors.newFixedThreadPool(input.getNumClients().intValue());
final Runnable testRun = () -> client.runTest(input.getIterations().intValue());
LOG.info("Test Started");
long startTime = System.nanoTime();
for (int i = 0; i < input.getNumClients().intValue(); i++) {
executor.submit(testRun);
}
executor.shutdown();
try {
executor.awaitTermination(testTimeout, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
LOG.error("Out of time: test did not finish within the {} min deadline ", testTimeout);
}
long endTime = System.nanoTime();
LOG.info("Test Done");
long elapsedTime = endTime - startTime;
StartTestOutput output = new StartTestOutputBuilder().setRate((long) 0).setGlobalRtcClientError(client.getRpcError()).setGlobalRtcClientOk(client.getRpcOk()).setExecTime(TimeUnit.NANOSECONDS.toMillis(elapsedTime)).setRate((client.getRpcOk() + client.getRpcError()) * 1000000000 / elapsedTime).build();
return RpcResultBuilder.success(output).buildFuture();
} finally {
for (RoutedRpcRegistration<?> routedRpcRegistration : rpcRegs) {
routedRpcRegistration.close();
}
}
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.
the class RoutedServiceIT method testServiceRegistration.
@Test
public void testServiceRegistration() {
assertNotNull(broker);
final BindingAwareProvider provider1 = new AbstractTestProvider() {
@Override
public void onSessionInitiated(final ProviderContext session) {
assertNotNull(session);
firstReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService1);
}
};
LOG.info("Register provider 1 with first implementation of routeSimpleService - service1");
broker.registerProvider(provider1);
assertNotNull("Registration should not be null", firstReg);
assertSame(odlRoutedService1, firstReg.getInstance());
final BindingAwareProvider provider2 = new AbstractTestProvider() {
@Override
public void onSessionInitiated(final ProviderContext session) {
assertNotNull(session);
secondReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService2);
}
};
LOG.info("Register provider 2 with second implementation of routeSimpleService - service2");
broker.registerProvider(provider2);
assertNotNull("Registration should not be null", firstReg);
assertSame(odlRoutedService2, secondReg.getInstance());
assertNotSame(secondReg, firstReg);
final BindingAwareConsumer consumer = session -> consumerService = session.getRpcService(OpendaylightTestRoutedRpcService.class);
LOG.info("Register routeService consumer");
broker.registerConsumer(consumer);
assertNotNull("MD-SAL instance of test Service should be returned", consumerService);
assertNotSame("Provider instance and consumer instance should not be same.", odlRoutedService1, consumerService);
final InstanceIdentifier<UnorderedList> nodeOnePath = createNodeRef("foo:node:1");
LOG.info("Provider 1 registers path of node 1");
firstReg.registerPath(TestContext.class, nodeOnePath);
/**
* Consumer creates addFlow message for node one and sends it to the
* MD-SAL
*/
final RoutedSimpleRouteInput simpleRouteFirstFoo = createSimpleRouteInput(nodeOnePath);
consumerService.routedSimpleRoute(simpleRouteFirstFoo);
/**
* Verifies that implementation of the first provider received the same
* message from MD-SAL.
*/
verify(odlRoutedService1).routedSimpleRoute(simpleRouteFirstFoo);
/**
* Verifies that second instance was not invoked with first message
*/
verify(odlRoutedService2, times(0)).routedSimpleRoute(simpleRouteFirstFoo);
LOG.info("Provider 2 registers path of node 2");
final InstanceIdentifier<UnorderedList> nodeTwo = createNodeRef("foo:node:2");
secondReg.registerPath(TestContext.class, nodeTwo);
/**
* Consumer sends message to nodeTwo for three times. Should be
* processed by second instance.
*/
final RoutedSimpleRouteInput simpleRouteSecondFoo = createSimpleRouteInput(nodeTwo);
consumerService.routedSimpleRoute(simpleRouteSecondFoo);
consumerService.routedSimpleRoute(simpleRouteSecondFoo);
consumerService.routedSimpleRoute(simpleRouteSecondFoo);
/**
* Verifies that second instance was invoked 3 times with second message
* and first instance wasn't invoked.
*/
verify(odlRoutedService2, times(3)).routedSimpleRoute(simpleRouteSecondFoo);
verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteSecondFoo);
LOG.info("Unregistration of the path for the node one in the first provider");
firstReg.unregisterPath(TestContext.class, nodeOnePath);
LOG.info("Provider 2 registers path of node 1");
secondReg.registerPath(TestContext.class, nodeOnePath);
/**
* A consumer sends third message to node 1
*/
final RoutedSimpleRouteInput simpleRouteThirdFoo = createSimpleRouteInput(nodeOnePath);
consumerService.routedSimpleRoute(simpleRouteThirdFoo);
/**
* Verifies that provider 1 wasn't invoked and provider 2 was invoked 1
* time.
* TODO: fix unregister path
*/
// verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteThirdFoo);
verify(odlRoutedService2).routedSimpleRoute(simpleRouteThirdFoo);
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.
the class DataServiceIT method test.
/**
* Ignored this, because classes here are constructed from
* very different class loader as MD-SAL is run into,
* this is code is run from different classloader.
*
* @throws Exception
*/
@Test
public void test() throws Exception {
BindingAwareConsumer consumer = session -> dataBroker = session.getSALService(DataBroker.class);
broker.registerConsumer(consumer);
assertNotNull(dataBroker);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
assertNotNull(transaction);
InstanceIdentifier<UnorderedList> node1 = createNodeRef("0");
Optional<UnorderedList> node = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, node1).checkedGet(5, TimeUnit.SECONDS);
assertFalse(node.isPresent());
UnorderedList nodeData1 = createNode("0");
transaction.put(LogicalDatastoreType.OPERATIONAL, node1, nodeData1);
transaction.submit().checkedGet(5, TimeUnit.SECONDS);
Optional<UnorderedList> readedData = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, node1).checkedGet(5, TimeUnit.SECONDS);
assertTrue(readedData.isPresent());
assertEquals(nodeData1.getKey(), readedData.get().getKey());
final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
assertNotNull(transaction2);
transaction2.delete(LogicalDatastoreType.OPERATIONAL, node1);
transaction2.submit().checkedGet(5, TimeUnit.SECONDS);
Optional<UnorderedList> readedData2 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, node1).checkedGet(5, TimeUnit.SECONDS);
assertFalse(readedData2.isPresent());
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testSeparateWrites.
@Test
public void testSeparateWrites() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
validateEvent(event);
}
Aggregations