@Deprecated @Override protected String createFlowName() { StringBuilder sb = new StringBuilder(); sb.append(OFRendererConstants.INTENT_L2_FLOW_NAME); sb.append(endPointGroups.get(OFRendererConstants.SRC_END_POINT_GROUP_INDEX)); sb.append(endPointGroups.get(OFRendererConstants.DST_END_POINT_GROUP_INDEX)); sb.append(intent.getId().getValue()); return sb.toString(); }
@Override protected Object doExecute() throws Exception { List<Intent> listIntents = provider.listIntents(isConfigurationData); if (listIntents.size() > 0) { StringBuilder sb = new StringBuilder(); Integer counter = 1; for (Intent intent : listIntents) { sb.append(String.format("#%d - id: %s\n", counter, intent.getId().getValue())); counter++; } return sb.toString(); } else { return String.format("No intents found. Check the logs for more details."); } } }
private boolean verifyIntent() { if (intent.getId() == null) { LOG.warn("Intent ID is not specified {}", intent); return false; } if (intent.getActions() == null || intent.getActions().size() > NUM_OF_SUPPORTED_ACTION) { LOG.warn("Intent's action is either null or there is more than {} action {}" , NUM_OF_SUPPORTED_ACTION, intent); return false; } if (intent.getSubjects() == null || intent.getSubjects().size() > NUM_OF_SUPPORTED_EPG) { LOG.warn("Intent's subjects is either null or there is more than {} subjects {}" , NUM_OF_SUPPORTED_EPG, intent); return false; } return true; }
/** * To set the redirect intent data * @param intent :intent */ private void addIntentToCache(Intent intent) { RedirectNodeData redirectNodeData; String intentId = intent.getId().getValue(); if (redirectNodeCache.get(intentId) == null) { redirectNodeData = new RedirectNodeData(); redirectNodeData.setIntent(intent); redirectNodeCache.put(intentId, redirectNodeData); } else { redirectNodeData = redirectNodeCache.get(intentId); redirectNodeData.setIntent(intent); } }
@Override public void execute(IntentUpdated event) { final Intent intent = event.getIntent(); stateMachineExecutorService.removeTransactions(intent.getId(), EventType.INTENT_UPDATE); stateMachineExecutorService.createTransaction(intent, EventType.INTENT_UPDATE); } };
/** * To get the action from the intent. * * @return action type. */ private String getAction(Intent intent) { Action action = intent.getActions().get(0).getAction(); String actionType = null; if (action instanceof Allow) { actionType = "allow"; } else if (action instanceof Block) { actionType = "block"; } else { throw new IntentElementNotFoundException("VTN Renderer supports only allow or block: {}" + intent.getId()); } return actionType; } }
sb.append(String.format("Intent Id: <%s>\n", intent.getId().getValue())); sb.append(String.format("Subjects: \n")); for (Subjects subjects : intent.getSubjects()) {
/** * @param buffer * the beginning string typed by the user * @param cursor * the position of the cursor * @param candidates * the list of completions proposed to the user */ @Override public int complete(String buffer, int cursor, List<String> candidates) { String query = (buffer == null) ? ".*" : buffer; if (!query.contains("*")) { query = query.concat(".*"); } StringsCompleter delegate = new StringsCompleter(); for (Intent intent : provider.listIntents(true)) { String id = intent.getId().getValue(); if (id.matches(query)) { candidates.add(id); delegate.getStrings().add(id); } } return delegate.complete(buffer, cursor, candidates); } }
@Override public void handleEvent(NicNotification event) { if (SecurityRuleAdded.class.isInstance(event)) { //Translate Security rules into intents SecurityRuleAdded securityRuleAdded = (SecurityRuleAdded) event; securityRule = securityRuleAdded.getSecurityRule(); Intent intent = createIntent(); ruleToIntentMap.put(securityRule.getSecurityRuleID(), intent.getId()); addIntentToMDSAL(intent, FlowAction.ADD_FLOW); } else if (SecurityRuleDeleted.class.isInstance(event)) { SecurityRuleDeleted securityRuleDeleted = (SecurityRuleDeleted) event; securityRule = (NeutronSecurityRule) securityRuleDeleted.getSecurityRule(); Uuid uuid = ruleToIntentMap.get(securityRule.getSecurityRuleID()); removeIntent(uuid); } else if(SecurityRuleUpdated.class.isInstance(event)) { //TODO: } }
public IntentBuilder(Intent base) { if (base.getKey() == null) { this._key = new IntentKey( base.getId() ); this._id = base.getId(); } else { this._key = base.getKey(); this._id = _key.getId(); } this._actions = base.getActions(); this._conditions = base.getConditions(); this._constraints = base.getConstraints(); this._detailedStatusMessage = base.getDetailedStatusMessage(); this._status = base.getStatus(); this._subjects = base.getSubjects(); if (base instanceof IntentImpl) { IntentImpl impl = (IntentImpl) base; if (!impl.augmentation.isEmpty()) { this.augmentation = new HashMap<>(impl.augmentation); } } else if (base instanceof AugmentationHolder) { @SuppressWarnings("unchecked") AugmentationHolder<org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intents.Intent> casted =(AugmentationHolder<org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intents.Intent>) base; if (!casted.augmentations().isEmpty()) { this.augmentation = new HashMap<>(casted.augmentations()); } } }
private List<Link> extractPathByFlowAction(final Intent intent, final FlowAction flowAction, final Constraints constraints) throws IntentInvalidException { List<Link> result = new ArrayList<>(); if (isProtectedOrSlowRoute(constraints)) { final EndPointGroup source = IntentUtils.extractSrcEndPointGroup(intent); final EndPointGroup target = IntentUtils.extractDstEndPointGroup(intent); switch (flowAction) { case ADD_FLOW: NetworkGraphManager.ProtectedLinks.put(intent, graphService.getDisjointPaths(extractNodeId(source), extractNodeId(target))); result = NetworkGraphManager.ProtectedLinks.get(intent).get(0); break; case REMOVE_FLOW: result = NetworkGraphManager.ProtectedLinks.get(intent).get(0); NetworkGraphManager.ProtectedLinks.remove(intent); break; default: graphService.getShortestPath(extractNodeId(source), extractNodeId(target)); } } if (result.isEmpty()) { throw new IntentInvalidException(NO_PATH_FOUND_MSG + intent.getId()); } return result; }
private void pushPortFlows(final ClassificationConstraint portConstraint, final NodeId nodeId, final FlowAction flowAction) { String portObject = ""; try { portObject = portConstraint.getClassificationConstraint().getClassifier(); } catch (NullPointerException npe) { throw new InvalidParameterException(CONSTRAINTS_NOT_FOUND_EXCEPTION + npe.getMessage()); } Gson gson = new Gson(); final NeutronSecurityRule securityRule = gson.fromJson(portObject, NeutronSecurityRule.class); final PortFlow portFlow = IntentFlowUtils.extractPortFlow(securityRule, endPointGroups); final Set<MatchBuilder> matchBuilders = portFlow.createPortRangeMatchBuilder(); for(MatchBuilder matchBuilder : matchBuilders) { final FlowBuilder flowBuilder = createFlowBuilder(matchBuilder); final Instructions builtInstructions = createOutputInstructions(OutputPortValues.NORMAL); flowBuilder.setInstructions(builtInstructions); flowName = portFlow.getFlowName(intent.getId().getValue()); writeDataTransaction(nodeId, flowBuilder, flowAction); } }
/** * This method parse the intent and calls the VTN renderer * */ private void intentParser(Intent intent) { if (!IntentUtils.verifyIntent(intent)) { return; } // Retrieve the Intent ID. String intentID = intent.getId().getValue(); // Retrieve the end points. final List<String> endPointGroups = IntentUtils.extractEndPointGroup(intent); String endPointSrc = endPointGroups.get(INDEX_OF_SRC_END_POINT_GROUP); String endPointDst = endPointGroups.get(INDEX_OF_DST_END_POINT_GROUP); // Get the type of the action. String actionType = getAction(intent); // get the encode UUID value String encodeUUID = vtnRendererUtility.encodeUUID(intentID); Status intentStatus = Status.CompletedError; // Convert the intent to VTN configuration. if (vtnIntentParser.containsIntentID(encodeUUID)) { intentStatus = vtnIntentParser.updateRendering(endPointSrc, endPointDst, actionType, intentID, encodeUUID, intent); } else { intentStatus = vtnIntentParser.rendering(endPointSrc, endPointDst, actionType, encodeUUID, intent); } LOG.trace("intent status: intentID={}, intentStatus={}", intentID, intentStatus); vtnRendererUtility.addIntent(intent, intentStatus); }
/** * Delete an intent information from the OPERATIONAL data store. * * @param intent The intent to be deleted from the OPERATIONAL data store. * * @return {@code true} if the intent is deleted successfully. */ public boolean deleteIntent(Intent intent) { MdsalUtils mdsal = new MdsalUtils(dataBroker); InstanceIdentifier<Intent> identifier = InstanceIdentifier.builder(Intents.class) .child(Intent.class, new IntentKey(intent.getId())) .build(); return mdsal.delete(LogicalDatastoreType.OPERATIONAL, identifier); }
/** * Redirect flow construction and deletion entry * @param intent : intent * @param flowAction :Add flow action */ public void redirectFlowConstruction(Intent intent, FlowAction flowAction) { if (intent == null || flowAction == null) { LOG.error("intent and action cannot be null"); return; } this.flowAction = flowAction; if (flowAction.equals(FlowAction.ADD_FLOW)) { addSfcNodeInfoToCache(intent); addIntentToCache(intent); } else if (flowAction.equals(FlowAction.REMOVE_FLOW)) { InstanceIdentifier<NetworkTopology> path = InstanceIdentifier.builder(NetworkTopology.class).build(); NetworkTopology networkTopology = mdsal.read(LogicalDatastoreType.OPERATIONAL, path); for (Topology topology : networkTopology.getTopology()) { for (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network .topology.rev131021.network.topology.topology.Node node : topology.getNode()) { removeRedirectFlow(new NodeId(node.getNodeId().getValue()), intent); LOG.info("Remove Redirect flow from switch: {}", node.getNodeId().getValue()); } } LOG.trace("Removed redirect intent data from cache {}", intent.getId().getValue()); redirectNodeCache.remove(intent.getId().getValue()); } }
} else { LOG.warn("Invalid address is specified in Intent configuration: {}", intent.getId()); return Status.CompletedError;
/** * To set the ingress and egress data to redirect cache * @param intent :intent */ private void addSfcNodeInfoToCache(Intent intent) { String intentId = intent.getId().getValue(); RedirectNodeData redirectNodeData = redirectNodeCache.get(intentId); if (redirectNodeData == null) { addIntentToCache(intent); redirectNodeData = redirectNodeCache.get(intentId); } Redirect actionContainer = (Redirect) intent.getActions().get(0).getAction(); org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.actions.action.redirect.Redirect redirectForService = actionContainer.getRedirect(); String serviceName = redirectForService.getServiceName(); String[] redirectSfcDataList = readRedirectSfcData(serviceName); redirectNodeData.setIngressNodeId(redirectSfcDataList[0]); redirectNodeData.setEgressNodeId(redirectSfcDataList[1]); deleteArpFlow(new NodeId(extractTopologyNodeId(redirectSfcDataList[0]).getValue())); deleteArpFlow(new NodeId(extractTopologyNodeId(redirectSfcDataList[1]).getValue())); }
/** * Put an operational information of an intent into the OPERATIONAL data store. * * @param intent The intent to be added into the OPERATIONAL data store. * @param status The intent status. * * @return {@code true} if the intent is added successfully. */ public boolean addIntent(Intent intent, Status status) { MdsalUtils mdsal = new MdsalUtils(dataBroker); InstanceIdentifier<Intent> identifier = InstanceIdentifier.builder(Intents.class) .child(Intent.class, new IntentKey(intent.getId())) .build(); Intent operationalIntent = new IntentBuilder(intent).setStatus(status).build(); return mdsal.put(LogicalDatastoreType.OPERATIONAL, identifier, operationalIntent); }