- RpcResultBuilder<GetNodeconnectorIdFromInterfaceOutput> rpcResultBuilder;
- try {
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
- InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker);
- String lowerLayerIf = ifState.getLowerLayerIf().get(0);
- NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
-
- GetNodeconnectorIdFromInterfaceOutputBuilder output = new GetNodeconnectorIdFromInterfaceOutputBuilder().setNodeconnectorId(nodeConnectorId);
- rpcResultBuilder = RpcResultBuilder.success();
- rpcResultBuilder.withResult(output.build());
- } catch (Exception e) {
- LOG.error("Retrieval of nodeconnector id for the key {} failed due to {}", interfaceName, e);
- rpcResultBuilder = RpcResultBuilder.failed();
- }
- return Futures.immediateFuture(rpcResultBuilder.build());
- }
-
- @Override
- public Future<RpcResult<GetInterfaceFromIfIndexOutput>> getInterfaceFromIfIndex(GetInterfaceFromIfIndexInput input) {
- Integer ifIndex = input.getIfIndex();
- RpcResultBuilder<GetInterfaceFromIfIndexOutput> rpcResultBuilder = null;
- try {
- InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class).child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
- Optional<IfIndexInterface> ifIndexesInterface = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, id, dataBroker);
- if(ifIndexesInterface.isPresent()) {
- String interfaceName = ifIndexesInterface.get().getInterfaceName();
- GetInterfaceFromIfIndexOutputBuilder output = new GetInterfaceFromIfIndexOutputBuilder().setInterfaceName(interfaceName);
- rpcResultBuilder = RpcResultBuilder.success();
- rpcResultBuilder.withResult(output.build());
- }
- } catch (Exception e) {
- LOG.error("Retrieval of interfaceName for the key {} failed due to {}", ifIndex, e);
- rpcResultBuilder = RpcResultBuilder.failed();
- }
- return Futures.immediateFuture(rpcResultBuilder.build());
- }
-
- @Override
- public Future<RpcResult<GetDpnInterfaceListOutput>> getDpnInterfaceList(GetDpnInterfaceListInput input) {
- BigInteger dpnid = input.getDpid();
- RpcResultBuilder<GetDpnInterfaceListOutput> rpcResultBuilder = null;
- try {
- InstanceIdentifier<DpnToInterface> id =
- InstanceIdentifier.builder(DpnToInterfaceList.class).child(DpnToInterface.class , new DpnToInterfaceKey(dpnid)).build();
- Optional<DpnToInterface> entry = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, id, dataBroker);
- if (entry.isPresent()) {
- List<InterfaceNameEntry> interfaceNameEntries = entry.get().getInterfaceNameEntry();
- if (interfaceNameEntries != null && !interfaceNameEntries.isEmpty()) {
- List<String> interfaceList = interfaceNameEntries.stream().map((a) -> a.getInterfaceName()).collect(Collectors.toList());
- GetDpnInterfaceListOutputBuilder output = new GetDpnInterfaceListOutputBuilder().setInterfacesList(interfaceList);
- rpcResultBuilder = RpcResultBuilder.success();
- rpcResultBuilder.withResult(output.build());
- }
- }
- } catch (Exception e) {
- LOG.error("Retrieval of interfaceNameList for the dpnId {} failed due to {}", dpnid, e);
- rpcResultBuilder = RpcResultBuilder.failed();
- }
- return Futures.immediateFuture(rpcResultBuilder.build());
- }
-
- protected static List<Instruction> buildInstructions(List<InstructionInfo> listInstructionInfo) {
- if (listInstructionInfo != null) {
- List<Instruction> instructions = new ArrayList<>();
- int instructionKey = 0;
-
- for (InstructionInfo instructionInfo : listInstructionInfo) {
- instructions.add(instructionInfo.buildInstruction(instructionKey));
- instructionKey++;
- }
- return instructions;
- }
-
- return null;
- }
-
- private ListenableFuture<Void> makeTerminatingServiceFlow(IfTunnel tunnelInfo, BigInteger dpnId, BigInteger tunnelKey, List<Instruction> instruction, int addOrRemove) {
- List<MatchInfo> mkMatches = new ArrayList<>();
- mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {tunnelKey}));
- short tableId = tunnelInfo.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE :
- NwConstants.EXTERNAL_TUNNEL_TABLE;
- final String flowRef = getFlowRef(dpnId,tableId, tunnelKey);
- Flow terminatingSerFlow = MDSALUtil.buildFlowNew(tableId, flowRef,
- 5, "TST Flow Entry", 0, 0,
- IfmConstants.TUNNEL_TABLE_COOKIE.add(tunnelKey), mkMatches, instruction);
- if (addOrRemove == NwConstants.ADD_FLOW) {
- return mdsalMgr.installFlow(dpnId, terminatingSerFlow);
- }
-
- return mdsalMgr.removeFlow(dpnId, terminatingSerFlow);