From d1c413ba8f93b7a93d4d5c1935a11087e0eae6a3 Mon Sep 17 00:00:00 2001 From: Yuta HIGUCHI Date: Tue, 20 Feb 2018 14:52:00 -0800 Subject: [PATCH] netconf RPC message parsing utils Change-Id: I23d0d1a95bff3f193601eaa792e7574b7cc621de --- protocols/netconf/api/gen-rpc.sh | 37 ++ .../onosproject/netconf/NetconfRpcError.java | 219 +++++++++++ .../netconf/NetconfRpcException.java | 96 +++++ .../netconf/NetconfRpcParserUtil.java | 184 ++++++++++ .../onosproject/netconf/NetconfRpcReply.java | 199 ++++++++++ .../netconf/rpc/EditOperationType.java | 76 ++++ .../netconf/rpc/ErrorInfoType.java | 179 +++++++++ .../netconf/rpc/ErrorSeverity.java | 67 ++++ .../org/onosproject/netconf/rpc/ErrorTag.java | 121 +++++++ .../onosproject/netconf/rpc/ErrorType.java | 73 ++++ .../org/onosproject/netconf/rpc/Hello.java | 183 ++++++++++ .../netconf/rpc/ObjectFactory.java | 277 ++++++++++++++ .../onosproject/netconf/rpc/RpcErrorType.java | 339 ++++++++++++++++++ .../netconf/rpc/RpcOperationType.java | 46 +++ .../onosproject/netconf/rpc/RpcReplyType.java | 199 ++++++++++ .../netconf/rpc/RpcResponseType.java | 46 +++ .../org/onosproject/netconf/rpc/RpcType.java | 131 +++++++ .../onosproject/netconf/rpc/package-info.java | 18 + .../netconf/NetconfRpcParserUtilTest.java | 328 +++++++++++++++++ 19 files changed, 2818 insertions(+) create mode 100755 protocols/netconf/api/gen-rpc.sh create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcError.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcException.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcParserUtil.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcReply.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/EditOperationType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorInfoType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorSeverity.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorTag.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/Hello.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ObjectFactory.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcErrorType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcOperationType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcReplyType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcResponseType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcType.java create mode 100644 protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/package-info.java create mode 100644 protocols/netconf/api/src/test/java/org/onosproject/netconf/NetconfRpcParserUtilTest.java diff --git a/protocols/netconf/api/gen-rpc.sh b/protocols/netconf/api/gen-rpc.sh new file mode 100755 index 0000000000..c3bd4d7e2e --- /dev/null +++ b/protocols/netconf/api/gen-rpc.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Generate code from XML schema +# it would be better to specify path to latest xjc (e.g., one with JDK9) +XJC=${XJC:-xjc} +$XJC -p org.onosproject.netconf.rpc -d src/main/java -no-header https://www.iana.org/assignments/xml-registry/schema/netconf.xsd + +# Adding Copyright header + checkstyle ignore comment +# patching javadoc syntax issue +for s in src/main/java/org/onosproject/netconf/rpc/*.java ; do + ed -s $s << EOF +H +0a +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF +. +w +,g/</s|>|\>| +. +w +EOF + chmod 444 $s +done diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcError.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcError.java new file mode 100644 index 0000000000..874dccdda1 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcError.java @@ -0,0 +1,219 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.netconf; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Serializable; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.xml.bind.JAXBElement; + +import org.onosproject.netconf.rpc.ErrorInfoType; +import org.onosproject.netconf.rpc.ErrorSeverity; +import org.onosproject.netconf.rpc.ErrorTag; +import org.onosproject.netconf.rpc.ErrorType; +import org.onosproject.netconf.rpc.RpcErrorType; +import org.onosproject.netconf.rpc.RpcErrorType.ErrorMessage; + +import com.google.common.annotations.Beta; +import com.google.common.base.MoreObjects; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; + +/** + * Wrapper around {@link RpcErrorType} for ease of handling and logging. + * + * @see NetconfRpcParserUtil + */ +@Beta +public class NetconfRpcError { + + /** + * Protocol mandated error-info: {@value}. + */ + public static final String BAD_ATTRIBUTE = "bad-attribute"; + /** + * Protocol mandated error-info: {@value}. + */ + public static final String BAD_ELEMENT = "bad-element"; + /** + * Protocol mandated error-info: {@value}. + */ + public static final String OK_ELEMENT = "ok-element"; + /** + * Protocol mandated error-info: {@value}. + */ + public static final String ERR_ELEMENT = "err-element"; + /** + * Protocol mandated error-info: {@value}. + */ + public static final String NOOP_ELEMENT = "noop-element"; + /** + * Protocol mandated error-info: {@value}. + */ + public static final String BAD_NAMESPACE = "bad-namespace"; + + private final RpcErrorType msg; + + + public static final NetconfRpcError wrap(RpcErrorType msg) { + return new NetconfRpcError(msg); + } + + protected NetconfRpcError(RpcErrorType msg) { + this.msg = checkNotNull(msg); + } + + /** + * Returns conceptual layer that the error occurred. + * + * @return the type + */ + public ErrorType type() { + return msg.getErrorType(); + } + + /** + * Returns a tag identifying the error condition. + * + * @return the tag + */ + public ErrorTag tag() { + return msg.getErrorTag(); + } + + /** + * Returns error severity. + * + * @return severity + */ + public ErrorSeverity severity() { + return msg.getErrorSeverity(); + } + + /** + * Returns a string identifying the data-model-specific + * or implementation-specific error condition, if one exists. + * + * @return app tag + */ + public Optional appTag() { + return Optional.ofNullable(msg.getErrorAppTag()); + } + + /** + * Returns absolute XPath expression identifying the element path + * to the node that is associated with the error being reported. + * + * @return XPath expression + */ + public Optional path() { + return Optional.ofNullable(msg.getErrorPath()); + } + + /** + * Returns human readable error message. + * + * @return message + */ + //@Nonnull + public String message() { + return Optional.ofNullable(msg.getErrorMessage()) + .map(ErrorMessage::getValue) + .orElse(""); + } + + /** + * Returns session-id in error-info if any. + * + * @return session-id + */ + public Optional infoSessionId() { + return Optional.ofNullable(msg.getErrorInfo()) + .map(ErrorInfoType::getSessionId); + } + + /** + * Returns protocol-mandated contents if any. + * + * @return Map containing protocol-mandated contents + *

+ * Possible Map keys: + * {@link #BAD_ATTRIBUTE}, + * {@link #BAD_ELEMENT}, + * {@link #OK_ELEMENT}, + * {@link #ERR_ELEMENT}, + * {@link #NOOP_ELEMENT}, + * {@link #BAD_NAMESPACE} + */ + @Beta + public Map info() { + return Optional.ofNullable(msg.getErrorInfo()) + .map(ErrorInfoType::getBadAttributeAndBadElementAndOkElement) + .map(Collection::stream) + .orElse(Stream.empty()) + .collect(Collectors., + String, String, Map> + toMap(elm -> elm.getName().getLocalPart(), + elm -> String.valueOf(elm.getValue()), + (v1, v2) -> v1, + LinkedHashMap::new)); + } + + /** + * Returns any other elements if present. + * + * @return any other elements + */ + @Beta + public List infoAny() { + return Optional.ofNullable(msg.getErrorInfo()) + .map(ErrorInfoType::getAny) + .orElse(ImmutableList.of()); + } + + /** + * Returns protocol- or data-model-specific error content. + * + * @return error info + */ + @Beta + public Optional rawInfo() { + return Optional.ofNullable(msg.getErrorInfo()); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("type", type()) + .add("tag", tag()) + .add("severity", severity()) + .add("appTag", appTag().orElse(null)) + .add("path", path().orElse(null)) + .add("message", Strings.emptyToNull(message())) + .add("info-session-id", infoSessionId().orElse(null)) + .add("info", info()) + .omitNullValues() + .toString(); + } +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcException.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcException.java new file mode 100644 index 0000000000..c5805d8678 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcException.java @@ -0,0 +1,96 @@ +/* + * Copyright 2017-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.netconf; + +import java.util.List; + +import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableList; + +/** + * Represents class of errors related to NETCONF rpc messaging. + */ +@Beta +public class NetconfRpcException extends RuntimeException { + + private static final long serialVersionUID = -5947975698207522820L; + + private final List error; + + /** + * @param errors RPC error message body + */ + public NetconfRpcException(List errors) { + super(getErrorMsg(errors)); + this.error = ImmutableList.copyOf(errors); + } + + /** + * @param errors RPC error message body + * @param message describing the error + */ + public NetconfRpcException(List errors, String message) { + super(message); + this.error = ImmutableList.copyOf(errors); + } + + /** + * @param errors RPC error message body + * @param cause of this exception + */ + public NetconfRpcException(List errors, Throwable cause) { + super(getErrorMsg(errors), cause); + this.error = ImmutableList.copyOf(errors); + } + + /** + * @param errors RPC error message body + * @param message describing the error + * @param cause of this exception + */ + public NetconfRpcException(List errors, String message, Throwable cause) { + super(message, cause); + this.error = ImmutableList.copyOf(errors); + } + + /** + * Retrieves rpc-error details. + * + * @return the rpc-errors + */ + public List rpcErrors() { + return error; + } + + + @Override + public String toString() { + return super.toString() + " " + error; + } + + /** + * Gets the first non-empty error message or {@code ""}. + * @param errors to fetch message from + * @return first non-empty error message or {@code ""} + */ + private static String getErrorMsg(List errors) { + return errors.stream() + .map(NetconfRpcError::message) + .filter(s -> !s.isEmpty()) + .findFirst().orElse(""); + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcParserUtil.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcParserUtil.java new file mode 100644 index 0000000000..2d25637d2a --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcParserUtil.java @@ -0,0 +1,184 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.netconf; + +import static org.slf4j.LoggerFactory.getLogger; + +import java.io.IOException; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamResult; + +import org.onosproject.netconf.rpc.RpcErrorType; +import org.slf4j.Logger; +import org.w3c.dom.Node; + +import com.google.common.annotations.Beta; +import com.google.common.io.CharSource; +import com.google.common.io.CharStreams; + +@Beta +public final class NetconfRpcParserUtil { + + private static final Logger log = getLogger(NetconfRpcParserUtil.class); + + /** + * Parse first rpc-reply contained in the input. + * + * @param xml input + * @return {@link NetconfRpcReply} or null on error + */ + public static NetconfRpcReply parseRpcReply(CharSequence xml) { + XMLInputFactory xif = XMLInputFactory.newFactory(); + try { + XMLStreamReader xsr = xif.createXMLStreamReader(CharSource.wrap(xml).openStream()); + return parseRpcReply(xsr); + } catch (XMLStreamException | IOException e) { + log.error("Exception thrown creating XMLStreamReader", e); + return null; + } + } + + /** + * Parse first rpc-reply contained in the input. + * + * @param xsr input + * @return {@link NetconfRpcReply} or null on error + */ + public static NetconfRpcReply parseRpcReply(XMLStreamReader xsr) { + try { + for ( ; xsr.hasNext(); xsr.next()) { + if (xsr.isStartElement() && + xsr.getName().getLocalPart().equals("rpc-reply")) { + + NetconfRpcReply.Builder builder = NetconfRpcReply.builder(); + String msgId = xsr.getAttributeValue(null, "message-id"); + builder.withMessageId(msgId); + xsr.nextTag(); + + return parseRpcReplyBody(builder, xsr); + } + } + } catch (XMLStreamException e) { + log.error("Exception thrown parsing rpc-reply", e); + } + return null; + } + + private static NetconfRpcReply parseRpcReplyBody(NetconfRpcReply.Builder builder, + XMLStreamReader xsr) { + + try { + for ( ; xsr.hasNext(); xsr.next()) { + if (xsr.isStartElement()) { + switch (xsr.getName().getLocalPart()) { + case "ok": + try { + // skip to end of tag event + xsr.getElementText(); + } catch (XMLStreamException e) { + log.warn("Failed parsing ok", e); + } + // ok should be the only element + return builder.buildOk(); + + case "rpc-error": + try { + JAXBContext context = JAXBContext.newInstance(RpcErrorType.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + JAXBElement error = unmarshaller.unmarshal(xsr, RpcErrorType.class); + builder.addError(NetconfRpcError.wrap(error.getValue())); + } catch (JAXBException e) { + log.warn("Failed parsing rpc-error", e); + } + break; + + default: // =rpc-response + QName qName = xsr.getName(); + try { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer t = tf.newTransformer(); + + t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + StringBuilder sb = new StringBuilder(); + t.transform(new StAXSource(xsr), + new StreamResult(CharStreams.asWriter(sb))); + builder.addResponses(sb.toString()); + } catch (TransformerException e) { + log.warn("Failed parsing {}", qName, e); + } + break; + } + } + } + } catch (XMLStreamException e) { + log.error("Exception thrown parsing rpc-reply body", e); + } + + return builder.build(); + + } + + /** + * Converts XML object into a String. + * + * @param xml Object (e.g., DOM {@link Node}) + * @return String representation of {@code xml} or empty on error. + */ + @Beta + public static String toString(Object xml) { + TransformerFactory tf = TransformerFactory.newInstance(); + try { + Transformer t = tf.newTransformer(); + t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + Source xmlSource = null; + if (xml instanceof Node) { + xmlSource = new DOMSource((Node) xml); + } else if (xml instanceof XMLEventReader) { + xmlSource = new StAXSource((XMLEventReader) xml); + } else if (xml instanceof XMLStreamReader) { + xmlSource = new StAXSource((XMLStreamReader) xml); + } else { + log.warn("Unknown XML object type: {}, {}", xml.getClass(), xml); + return ""; + } + + StringBuilder sb = new StringBuilder(); + t.transform(xmlSource, new StreamResult(CharStreams.asWriter(sb))); + return sb.toString(); + } catch (TransformerException | XMLStreamException e) { + log.error("Exception thrown", e); + return ""; + } + } + + private NetconfRpcParserUtil() {} + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcReply.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcReply.java new file mode 100644 index 0000000000..7aa6e00521 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfRpcReply.java @@ -0,0 +1,199 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.netconf; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; + +import org.slf4j.Logger; +import com.google.common.annotations.Beta; +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + +/** + * Representation of rpc-reply. + * + * @see NetconfRpcParserUtil + */ +@Beta +public class NetconfRpcReply { + + private static final Logger log = getLogger(NetconfRpcReply.class); + + public enum Type { + OK, + ERROR, + RESPONSE + } + + private final Set replies; + + private final String messageId; + + // rpc-reply is ok or (0+ rpc-error and/or 0+ rpc-response) + + private final List errors; + private final List responses; + + protected NetconfRpcReply(NetconfRpcReply.Builder builder) { + this.messageId = checkNotNull(builder.messageId); + this.replies = ImmutableSet.copyOf(builder.replies); + this.errors = ImmutableList.copyOf(builder.errors); + this.responses = ImmutableList.copyOf(builder.responses); + } + + /** + * Returns message-id of this message. + * + * @return message-id + */ + //@Nonnull + public String messageId() { + return messageId; + } + + /** + * Returns true if ok reply. + * + * @return true if ok reply. + */ + public boolean isOk() { + return replies.contains(Type.OK); + } + + /** + * Returns true if reply contains rpc-error. + * + * @return true if reply contains rpc-error + */ + public boolean hasError() { + return replies.contains(Type.ERROR); + } + + /** + * Returns list of rpc-errors in rpc-reply. + * + * @return list of rpc-errors in rpc-reply. + */ + public List errors() { + return errors; + } + + /** + * Returns list of rpc responses in rpc-reply. + * + * @return list of rpc responses in rpc-reply. + */ + public List responses() { + return responses; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("messageId", messageId) + .add("replies", replies) + .add("errors", errors) + .add("responses", responses) + .toString(); + } + + /** + * Creates builder to build {@link NetconfRpcReply}. + * @return created builder + */ + public static NetconfRpcReply.Builder builder() { + return new Builder(); + } + + /** + * Builder to build {@link NetconfRpcReply}. + */ + public static final class Builder { + private String messageId; + private Set replies = EnumSet.noneOf(NetconfRpcReply.Type.class); + private List errors = new ArrayList<>(); + private List responses = new ArrayList<>(); + + private Builder() {} + + /** + * Builder method to set message-id. + * + * @param messageId field to set + * @return builder + */ + public NetconfRpcReply.Builder withMessageId(String messageId) { + this.messageId = messageId; + return this; + } + + /** + * Builder method to adding error parameter. + * + * @param error field to add + * @return builder + */ + public NetconfRpcReply.Builder addError(NetconfRpcError error) { + this.replies.add(Type.ERROR); + this.errors.add(error); + return this; + } + + /** + * Builder method for adding response parameter. + * + * @param response field to add + * @return builder + */ + public NetconfRpcReply.Builder addResponses(String response) { + this.replies.add(Type.RESPONSE); + this.responses.add(response); + return this; + } + + /** + * Builds ok reply message. + * @return ok + */ + public NetconfRpcReply buildOk() { + if (!replies.isEmpty()) { + log.warn("Unexpected item in replies area: {}", replies); + } + this.replies.add(Type.OK); + return build(); + } + + /** + * Builder method of the builder. + * + * @return built class + */ + public NetconfRpcReply build() { + if (replies.isEmpty()) { + log.warn("Empty rpc-reply?"); + } + return new NetconfRpcReply(this); + } + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/EditOperationType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/EditOperationType.java new file mode 100644 index 0000000000..d0b968ab6b --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/EditOperationType.java @@ -0,0 +1,76 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for editOperationType. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="editOperationType">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="merge"/>
+ *     <enumeration value="replace"/>
+ *     <enumeration value="create"/>
+ *     <enumeration value="delete"/>
+ *     <enumeration value="remove"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "editOperationType") +@XmlEnum +public enum EditOperationType { + + @XmlEnumValue("merge") + MERGE("merge"), + @XmlEnumValue("replace") + REPLACE("replace"), + @XmlEnumValue("create") + CREATE("create"), + @XmlEnumValue("delete") + DELETE("delete"), + @XmlEnumValue("remove") + REMOVE("remove"); + private final String value; + + EditOperationType(String v) { + value = v; + } + + public String value() { + return value; + } + + public static EditOperationType fromValue(String v) { + for (EditOperationType c: EditOperationType.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorInfoType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorInfoType.java new file mode 100644 index 0000000000..d780fc1e44 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorInfoType.java @@ -0,0 +1,179 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + + +/** + *

Java class for errorInfoType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="errorInfoType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <choice>
+ *           <element name="session-id" type="{urn:ietf:params:xml:ns:netconf:base:1.0}SessionIdOrZero"/>
+ *           <sequence maxOccurs="unbounded" minOccurs="0">
+ *             <sequence>
+ *               <element name="bad-attribute" type="{http://www.w3.org/2001/XMLSchema}QName" minOccurs="0"/>
+ *               <element name="bad-element" type="{http://www.w3.org/2001/XMLSchema}QName" minOccurs="0"/>
+ *               <element name="ok-element" type="{http://www.w3.org/2001/XMLSchema}QName" minOccurs="0"/>
+ *               <element name="err-element" type="{http://www.w3.org/2001/XMLSchema}QName" minOccurs="0"/>
+ *               <element name="noop-element" type="{http://www.w3.org/2001/XMLSchema}QName" minOccurs="0"/>
+ *               <element name="bad-namespace" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *             </sequence>
+ *           </sequence>
+ *         </choice>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "errorInfoType", propOrder = { + "sessionId", + "badAttributeAndBadElementAndOkElement", + "any" +}) +public class ErrorInfoType { + + @XmlElement(name = "session-id") + @XmlSchemaType(name = "unsignedInt") + protected Long sessionId; + @XmlElementRefs({ + @XmlElementRef(name = "bad-attribute", namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", type = JAXBElement.class, required = false), + @XmlElementRef(name = "bad-element", namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", type = JAXBElement.class, required = false), + @XmlElementRef(name = "ok-element", namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", type = JAXBElement.class, required = false), + @XmlElementRef(name = "err-element", namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", type = JAXBElement.class, required = false), + @XmlElementRef(name = "noop-element", namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", type = JAXBElement.class, required = false), + @XmlElementRef(name = "bad-namespace", namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", type = JAXBElement.class, required = false) + }) + protected List> badAttributeAndBadElementAndOkElement; + @XmlAnyElement(lax = true) + protected List any; + + /** + * Gets the value of the sessionId property. + * + * @return + * possible object is + * {@link Long } + * + */ + public Long getSessionId() { + return sessionId; + } + + /** + * Sets the value of the sessionId property. + * + * @param value + * allowed object is + * {@link Long } + * + */ + public void setSessionId(Long value) { + this.sessionId = value; + } + + /** + * Gets the value of the badAttributeAndBadElementAndOkElement property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the badAttributeAndBadElementAndOkElement property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getBadAttributeAndBadElementAndOkElement().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link JAXBElement }{@code <}{@link QName }{@code >} + * {@link JAXBElement }{@code <}{@link QName }{@code >} + * {@link JAXBElement }{@code <}{@link QName }{@code >} + * {@link JAXBElement }{@code <}{@link QName }{@code >} + * {@link JAXBElement }{@code <}{@link QName }{@code >} + * {@link JAXBElement }{@code <}{@link String }{@code >} + * + * + */ + public List> getBadAttributeAndBadElementAndOkElement() { + if (badAttributeAndBadElementAndOkElement == null) { + badAttributeAndBadElementAndOkElement = new ArrayList>(); + } + return this.badAttributeAndBadElementAndOkElement; + } + + /** + * Gets the value of the any property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the any property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getAny().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Element } + * {@link Object } + * + * + */ + public List getAny() { + if (any == null) { + any = new ArrayList(); + } + return this.any; + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorSeverity.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorSeverity.java new file mode 100644 index 0000000000..ff7a7e781a --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorSeverity.java @@ -0,0 +1,67 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for ErrorSeverity. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="ErrorSeverity">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="error"/>
+ *     <enumeration value="warning"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "ErrorSeverity") +@XmlEnum +public enum ErrorSeverity { + + @XmlEnumValue("error") + ERROR("error"), + @XmlEnumValue("warning") + WARNING("warning"); + private final String value; + + ErrorSeverity(String v) { + value = v; + } + + public String value() { + return value; + } + + public static ErrorSeverity fromValue(String v) { + for (ErrorSeverity c: ErrorSeverity.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorTag.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorTag.java new file mode 100644 index 0000000000..fd69b8febd --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorTag.java @@ -0,0 +1,121 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for ErrorTag. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="ErrorTag">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="in-use"/>
+ *     <enumeration value="invalid-value"/>
+ *     <enumeration value="too-big"/>
+ *     <enumeration value="missing-attribute"/>
+ *     <enumeration value="bad-attribute"/>
+ *     <enumeration value="unknown-attribute"/>
+ *     <enumeration value="missing-element"/>
+ *     <enumeration value="bad-element"/>
+ *     <enumeration value="unknown-element"/>
+ *     <enumeration value="unknown-namespace"/>
+ *     <enumeration value="access-denied"/>
+ *     <enumeration value="lock-denied"/>
+ *     <enumeration value="resource-denied"/>
+ *     <enumeration value="rollback-failed"/>
+ *     <enumeration value="data-exists"/>
+ *     <enumeration value="data-missing"/>
+ *     <enumeration value="operation-not-supported"/>
+ *     <enumeration value="operation-failed"/>
+ *     <enumeration value="partial-operation"/>
+ *     <enumeration value="malformed-message"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "ErrorTag") +@XmlEnum +public enum ErrorTag { + + @XmlEnumValue("in-use") + IN_USE("in-use"), + @XmlEnumValue("invalid-value") + INVALID_VALUE("invalid-value"), + @XmlEnumValue("too-big") + TOO_BIG("too-big"), + @XmlEnumValue("missing-attribute") + MISSING_ATTRIBUTE("missing-attribute"), + @XmlEnumValue("bad-attribute") + BAD_ATTRIBUTE("bad-attribute"), + @XmlEnumValue("unknown-attribute") + UNKNOWN_ATTRIBUTE("unknown-attribute"), + @XmlEnumValue("missing-element") + MISSING_ELEMENT("missing-element"), + @XmlEnumValue("bad-element") + BAD_ELEMENT("bad-element"), + @XmlEnumValue("unknown-element") + UNKNOWN_ELEMENT("unknown-element"), + @XmlEnumValue("unknown-namespace") + UNKNOWN_NAMESPACE("unknown-namespace"), + @XmlEnumValue("access-denied") + ACCESS_DENIED("access-denied"), + @XmlEnumValue("lock-denied") + LOCK_DENIED("lock-denied"), + @XmlEnumValue("resource-denied") + RESOURCE_DENIED("resource-denied"), + @XmlEnumValue("rollback-failed") + ROLLBACK_FAILED("rollback-failed"), + @XmlEnumValue("data-exists") + DATA_EXISTS("data-exists"), + @XmlEnumValue("data-missing") + DATA_MISSING("data-missing"), + @XmlEnumValue("operation-not-supported") + OPERATION_NOT_SUPPORTED("operation-not-supported"), + @XmlEnumValue("operation-failed") + OPERATION_FAILED("operation-failed"), + @XmlEnumValue("partial-operation") + PARTIAL_OPERATION("partial-operation"), + @XmlEnumValue("malformed-message") + MALFORMED_MESSAGE("malformed-message"); + private final String value; + + ErrorTag(String v) { + value = v; + } + + public String value() { + return value; + } + + public static ErrorTag fromValue(String v) { + for (ErrorTag c: ErrorTag.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorType.java new file mode 100644 index 0000000000..3d86610c14 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ErrorType.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for ErrorType. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="ErrorType">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="transport"/>
+ *     <enumeration value="rpc"/>
+ *     <enumeration value="protocol"/>
+ *     <enumeration value="application"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "ErrorType") +@XmlEnum +public enum ErrorType { + + @XmlEnumValue("transport") + TRANSPORT("transport"), + @XmlEnumValue("rpc") + RPC("rpc"), + @XmlEnumValue("protocol") + PROTOCOL("protocol"), + @XmlEnumValue("application") + APPLICATION("application"); + private final String value; + + ErrorType(String v) { + value = v; + } + + public String value() { + return value; + } + + public static ErrorType fromValue(String v) { + for (ErrorType c: ErrorType.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/Hello.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/Hello.java new file mode 100644 index 0000000000..220e8a8c77 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/Hello.java @@ -0,0 +1,183 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="capabilities">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="capability" type="{http://www.w3.org/2001/XMLSchema}anyURI" maxOccurs="unbounded"/>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="session-id" type="{urn:ietf:params:xml:ns:netconf:base:1.0}SessionId" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "capabilities", + "sessionId" +}) +@XmlRootElement(name = "hello") +public class Hello { + + @XmlElement(required = true) + protected Hello.Capabilities capabilities; + @XmlElement(name = "session-id") + @XmlSchemaType(name = "unsignedInt") + protected Long sessionId; + + /** + * Gets the value of the capabilities property. + * + * @return + * possible object is + * {@link Hello.Capabilities } + * + */ + public Hello.Capabilities getCapabilities() { + return capabilities; + } + + /** + * Sets the value of the capabilities property. + * + * @param value + * allowed object is + * {@link Hello.Capabilities } + * + */ + public void setCapabilities(Hello.Capabilities value) { + this.capabilities = value; + } + + /** + * Gets the value of the sessionId property. + * + * @return + * possible object is + * {@link Long } + * + */ + public Long getSessionId() { + return sessionId; + } + + /** + * Sets the value of the sessionId property. + * + * @param value + * allowed object is + * {@link Long } + * + */ + public void setSessionId(Long value) { + this.sessionId = value; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="capability" type="{http://www.w3.org/2001/XMLSchema}anyURI" maxOccurs="unbounded"/>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "capability" + }) + public static class Capabilities { + + @XmlElement(required = true) + @XmlSchemaType(name = "anyURI") + protected List capability; + + /** + * Gets the value of the capability property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the capability property. + * + *

+ * For example, to add a new item, do as follows: + *

+         *    getCapability().add(newItem);
+         * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getCapability() { + if (capability == null) { + capability = new ArrayList(); + } + return this.capability; + } + + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ObjectFactory.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ObjectFactory.java new file mode 100644 index 0000000000..2328f26b7c --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/ObjectFactory.java @@ -0,0 +1,277 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the org.onosproject.netconf.rpc package. + *

An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _Rpc_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "rpc"); + private final static QName _RpcReply_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "rpc-reply"); + private final static QName _RpcError_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "rpc-error"); + private final static QName _RpcOperation_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "rpcOperation"); + private final static QName _RpcResponse_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "rpcResponse"); + private final static QName _ErrorInfoTypeBadAttribute_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "bad-attribute"); + private final static QName _ErrorInfoTypeBadElement_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "bad-element"); + private final static QName _ErrorInfoTypeOkElement_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "ok-element"); + private final static QName _ErrorInfoTypeErrElement_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "err-element"); + private final static QName _ErrorInfoTypeNoopElement_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "noop-element"); + private final static QName _ErrorInfoTypeBadNamespace_QNAME = new QName("urn:ietf:params:xml:ns:netconf:base:1.0", "bad-namespace"); + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.onosproject.netconf.rpc + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Hello } + * + */ + public Hello createHello() { + return new Hello(); + } + + /** + * Create an instance of {@link RpcErrorType } + * + */ + public RpcErrorType createRpcErrorType() { + return new RpcErrorType(); + } + + /** + * Create an instance of {@link RpcType } + * + */ + public RpcType createRpcType() { + return new RpcType(); + } + + /** + * Create an instance of {@link RpcReplyType } + * + */ + public RpcReplyType createRpcReplyType() { + return new RpcReplyType(); + } + + /** + * Create an instance of {@link RpcOperationType } + * + */ + public RpcOperationType createRpcOperationType() { + return new RpcOperationType(); + } + + /** + * Create an instance of {@link RpcResponseType } + * + */ + public RpcResponseType createRpcResponseType() { + return new RpcResponseType(); + } + + /** + * Create an instance of {@link Hello.Capabilities } + * + */ + public Hello.Capabilities createHelloCapabilities() { + return new Hello.Capabilities(); + } + + /** + * Create an instance of {@link ErrorInfoType } + * + */ + public ErrorInfoType createErrorInfoType() { + return new ErrorInfoType(); + } + + /** + * Create an instance of {@link RpcErrorType.ErrorMessage } + * + */ + public RpcErrorType.ErrorMessage createRpcErrorTypeErrorMessage() { + return new RpcErrorType.ErrorMessage(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link RpcType }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link RpcType }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "rpc") + public JAXBElement createRpc(RpcType value) { + return new JAXBElement(_Rpc_QNAME, RpcType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link RpcReplyType }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link RpcReplyType }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "rpc-reply") + public JAXBElement createRpcReply(RpcReplyType value) { + return new JAXBElement(_RpcReply_QNAME, RpcReplyType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link RpcErrorType }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link RpcErrorType }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "rpc-error") + public JAXBElement createRpcError(RpcErrorType value) { + return new JAXBElement(_RpcError_QNAME, RpcErrorType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link RpcOperationType }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link RpcOperationType }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "rpcOperation") + public JAXBElement createRpcOperation(RpcOperationType value) { + return new JAXBElement(_RpcOperation_QNAME, RpcOperationType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link RpcResponseType }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link RpcResponseType }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "rpcResponse") + public JAXBElement createRpcResponse(RpcResponseType value) { + return new JAXBElement(_RpcResponse_QNAME, RpcResponseType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "bad-attribute", scope = ErrorInfoType.class) + public JAXBElement createErrorInfoTypeBadAttribute(QName value) { + return new JAXBElement(_ErrorInfoTypeBadAttribute_QNAME, QName.class, ErrorInfoType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "bad-element", scope = ErrorInfoType.class) + public JAXBElement createErrorInfoTypeBadElement(QName value) { + return new JAXBElement(_ErrorInfoTypeBadElement_QNAME, QName.class, ErrorInfoType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "ok-element", scope = ErrorInfoType.class) + public JAXBElement createErrorInfoTypeOkElement(QName value) { + return new JAXBElement(_ErrorInfoTypeOkElement_QNAME, QName.class, ErrorInfoType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "err-element", scope = ErrorInfoType.class) + public JAXBElement createErrorInfoTypeErrElement(QName value) { + return new JAXBElement(_ErrorInfoTypeErrElement_QNAME, QName.class, ErrorInfoType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link QName }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "noop-element", scope = ErrorInfoType.class) + public JAXBElement createErrorInfoTypeNoopElement(QName value) { + return new JAXBElement(_ErrorInfoTypeNoopElement_QNAME, QName.class, ErrorInfoType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link String }{@code >} + */ + @XmlElementDecl(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", name = "bad-namespace", scope = ErrorInfoType.class) + public JAXBElement createErrorInfoTypeBadNamespace(String value) { + return new JAXBElement(_ErrorInfoTypeBadNamespace_QNAME, String.class, ErrorInfoType.class, value); + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcErrorType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcErrorType.java new file mode 100644 index 0000000000..87490bb4cb --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcErrorType.java @@ -0,0 +1,339 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + + +/** + *

Java class for rpcErrorType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="rpcErrorType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="error-type" type="{urn:ietf:params:xml:ns:netconf:base:1.0}ErrorType"/>
+ *         <element name="error-tag" type="{urn:ietf:params:xml:ns:netconf:base:1.0}ErrorTag"/>
+ *         <element name="error-severity" type="{urn:ietf:params:xml:ns:netconf:base:1.0}ErrorSeverity"/>
+ *         <element name="error-app-tag" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="error-path" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="error-message" minOccurs="0">
+ *           <complexType>
+ *             <simpleContent>
+ *               <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *                 <attribute ref="{http://www.w3.org/XML/1998/namespace}lang"/>
+ *               </extension>
+ *             </simpleContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="error-info" type="{urn:ietf:params:xml:ns:netconf:base:1.0}errorInfoType" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "rpcErrorType", propOrder = { + "errorType", + "errorTag", + "errorSeverity", + "errorAppTag", + "errorPath", + "errorMessage", + "errorInfo" +}) +public class RpcErrorType { + + @XmlElement(name = "error-type", required = true) + @XmlSchemaType(name = "string") + protected ErrorType errorType; + @XmlElement(name = "error-tag", required = true) + @XmlSchemaType(name = "string") + protected ErrorTag errorTag; + @XmlElement(name = "error-severity", required = true) + @XmlSchemaType(name = "string") + protected ErrorSeverity errorSeverity; + @XmlElement(name = "error-app-tag") + protected String errorAppTag; + @XmlElement(name = "error-path") + protected String errorPath; + @XmlElement(name = "error-message") + protected RpcErrorType.ErrorMessage errorMessage; + @XmlElement(name = "error-info") + protected ErrorInfoType errorInfo; + + /** + * Gets the value of the errorType property. + * + * @return + * possible object is + * {@link ErrorType } + * + */ + public ErrorType getErrorType() { + return errorType; + } + + /** + * Sets the value of the errorType property. + * + * @param value + * allowed object is + * {@link ErrorType } + * + */ + public void setErrorType(ErrorType value) { + this.errorType = value; + } + + /** + * Gets the value of the errorTag property. + * + * @return + * possible object is + * {@link ErrorTag } + * + */ + public ErrorTag getErrorTag() { + return errorTag; + } + + /** + * Sets the value of the errorTag property. + * + * @param value + * allowed object is + * {@link ErrorTag } + * + */ + public void setErrorTag(ErrorTag value) { + this.errorTag = value; + } + + /** + * Gets the value of the errorSeverity property. + * + * @return + * possible object is + * {@link ErrorSeverity } + * + */ + public ErrorSeverity getErrorSeverity() { + return errorSeverity; + } + + /** + * Sets the value of the errorSeverity property. + * + * @param value + * allowed object is + * {@link ErrorSeverity } + * + */ + public void setErrorSeverity(ErrorSeverity value) { + this.errorSeverity = value; + } + + /** + * Gets the value of the errorAppTag property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getErrorAppTag() { + return errorAppTag; + } + + /** + * Sets the value of the errorAppTag property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setErrorAppTag(String value) { + this.errorAppTag = value; + } + + /** + * Gets the value of the errorPath property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getErrorPath() { + return errorPath; + } + + /** + * Sets the value of the errorPath property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setErrorPath(String value) { + this.errorPath = value; + } + + /** + * Gets the value of the errorMessage property. + * + * @return + * possible object is + * {@link RpcErrorType.ErrorMessage } + * + */ + public RpcErrorType.ErrorMessage getErrorMessage() { + return errorMessage; + } + + /** + * Sets the value of the errorMessage property. + * + * @param value + * allowed object is + * {@link RpcErrorType.ErrorMessage } + * + */ + public void setErrorMessage(RpcErrorType.ErrorMessage value) { + this.errorMessage = value; + } + + /** + * Gets the value of the errorInfo property. + * + * @return + * possible object is + * {@link ErrorInfoType } + * + */ + public ErrorInfoType getErrorInfo() { + return errorInfo; + } + + /** + * Sets the value of the errorInfo property. + * + * @param value + * allowed object is + * {@link ErrorInfoType } + * + */ + public void setErrorInfo(ErrorInfoType value) { + this.errorInfo = value; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <simpleContent>
+     *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+     *       <attribute ref="{http://www.w3.org/XML/1998/namespace}lang"/>
+     *     </extension>
+     *   </simpleContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "value" + }) + public static class ErrorMessage { + + @XmlValue + protected String value; + @XmlAttribute(name = "lang", namespace = "http://www.w3.org/XML/1998/namespace") + protected String lang; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcOperationType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcOperationType.java new file mode 100644 index 0000000000..4e6580f583 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcOperationType.java @@ -0,0 +1,46 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for rpcOperationType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="rpcOperationType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "rpcOperationType") +public class RpcOperationType { + + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcReplyType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcReplyType.java new file mode 100644 index 0000000000..83d30d9a2b --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcReplyType.java @@ -0,0 +1,199 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + + +/** + *

Java class for rpcReplyType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="rpcReplyType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <choice>
+ *         <element name="ok" type="{http://www.w3.org/2001/XMLSchema}anyType"/>
+ *         <sequence>
+ *           <element ref="{urn:ietf:params:xml:ns:netconf:base:1.0}rpc-error" maxOccurs="unbounded" minOccurs="0"/>
+ *           <element ref="{urn:ietf:params:xml:ns:netconf:base:1.0}rpcResponse" maxOccurs="unbounded" minOccurs="0"/>
+ *         </sequence>
+ *       </choice>
+ *       <attribute name="message-id" type="{urn:ietf:params:xml:ns:netconf:base:1.0}messageIdType" />
+ *       <anyAttribute processContents='lax'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "rpcReplyType", propOrder = { + "ok", + "rpcError", + "rpcResponse" +}) +public class RpcReplyType { + + protected Object ok; + @XmlElement(name = "rpc-error") + protected List rpcError; + protected List rpcResponse; + @XmlAttribute(name = "message-id") + protected String messageId; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the ok property. + * + * @return + * possible object is + * {@link Object } + * + */ + public Object getOk() { + return ok; + } + + /** + * Sets the value of the ok property. + * + * @param value + * allowed object is + * {@link Object } + * + */ + public void setOk(Object value) { + this.ok = value; + } + + /** + * Gets the value of the rpcError property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the rpcError property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getRpcError().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link RpcErrorType } + * + * + */ + public List getRpcError() { + if (rpcError == null) { + rpcError = new ArrayList(); + } + return this.rpcError; + } + + /** + * Gets the value of the rpcResponse property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the rpcResponse property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getRpcResponse().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link RpcResponseType } + * + * + */ + public List getRpcResponse() { + if (rpcResponse == null) { + rpcResponse = new ArrayList(); + } + return this.rpcResponse; + } + + /** + * Gets the value of the messageId property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMessageId() { + return messageId; + } + + /** + * Sets the value of the messageId property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMessageId(String value) { + this.messageId = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

+ * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcResponseType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcResponseType.java new file mode 100644 index 0000000000..edcf940e23 --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcResponseType.java @@ -0,0 +1,46 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for rpcResponseType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="rpcResponseType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "rpcResponseType") +public class RpcResponseType { + + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcType.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcType.java new file mode 100644 index 0000000000..713438d5bd --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/RpcType.java @@ -0,0 +1,131 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF + +package org.onosproject.netconf.rpc; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + + +/** + *

Java class for rpcType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="rpcType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{urn:ietf:params:xml:ns:netconf:base:1.0}rpcOperation"/>
+ *       </sequence>
+ *       <attribute name="message-id" use="required" type="{urn:ietf:params:xml:ns:netconf:base:1.0}messageIdType" />
+ *       <anyAttribute processContents='lax'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "rpcType", propOrder = { + "rpcOperation" +}) +public class RpcType { + + @XmlElement(required = true) + protected RpcOperationType rpcOperation; + @XmlAttribute(name = "message-id", required = true) + protected String messageId; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the rpcOperation property. + * + * @return + * possible object is + * {@link RpcOperationType } + * + */ + public RpcOperationType getRpcOperation() { + return rpcOperation; + } + + /** + * Sets the value of the rpcOperation property. + * + * @param value + * allowed object is + * {@link RpcOperationType } + * + */ + public void setRpcOperation(RpcOperationType value) { + this.rpcOperation = value; + } + + /** + * Gets the value of the messageId property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMessageId() { + return messageId; + } + + /** + * Sets the value of the messageId property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMessageId(String value) { + this.messageId = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

+ * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/package-info.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/package-info.java new file mode 100644 index 0000000000..ff97d41e7a --- /dev/null +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/rpc/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +// CHECKSTYLE:OFF +@javax.xml.bind.annotation.XmlSchema(namespace = "urn:ietf:params:xml:ns:netconf:base:1.0", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +package org.onosproject.netconf.rpc; diff --git a/protocols/netconf/api/src/test/java/org/onosproject/netconf/NetconfRpcParserUtilTest.java b/protocols/netconf/api/src/test/java/org/onosproject/netconf/NetconfRpcParserUtilTest.java new file mode 100644 index 0000000000..902651df45 --- /dev/null +++ b/protocols/netconf/api/src/test/java/org/onosproject/netconf/NetconfRpcParserUtilTest.java @@ -0,0 +1,328 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.netconf; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Test; +import org.onosproject.netconf.rpc.ErrorSeverity; +import org.onosproject.netconf.rpc.ErrorTag; +import org.onosproject.netconf.rpc.ErrorType; +import org.w3c.dom.Node; + +public class NetconfRpcParserUtilTest { + + static final String OK_DATA1 = + "\n" + + " \n" + + "\n"; + + static final String ERROR_XPATH1 = + "/rpc/edit-config/config/oc-if:interfaces/oc-if:interface[oc-if:name='foo']/oc-if:config/oc-if:type"; + + static final String ERROR_DATA1 = + "\n" + + " \n" + + " application\n" + + " invalid-value\n" + + " error\n" + + " \n" + + " /rpc/edit-config/config/oc-if:interfaces/oc-if:interface[oc-if:name='foo']/oc-if:config/oc-if:type\n" + + " \n" + + " \"fastEther\" is not a valid value.\n" + + " \n" + + " type\n" + + " value" + + " \n" + + " \n" + + ""; + + static final String RESPONSE_BODY1 = + "\n" + + " \n" + + " \n" + + " foo\n" + + " \n" + + " foo\n" + + " ianaift:fastEther\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " comp1\n" + + " \n" + + " comp1\n" + + " \n" + + " \n" + + " \n" + + " comp2\n" + + " \n" + + " comp2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " admin\n" + + " 9000\n" + + " 20\n" + + " $1$3iwdPGZ1$PBh0MaDjzSFf1jozKYJUI1\n" + + " /var/confd/homes/admin/.ssh\n" + + " /var/confd/homes/admin\n" + + " \n" + + " \n" + + " oper\n" + + " 9000\n" + + " 20\n" + + " $1$hJImrsyG$Ey294aLU/8wE.Y5vgjqzm/\n" + + " /var/confd/homes/oper/.ssh\n" + + " /var/confd/homes/oper\n" + + " \n" + + " \n" + + " private\n" + + " 9000\n" + + " 20\n" + + " $1$f85WqsO0$GdtqBqa0yAZXXm5sSCv/M/\n" + + " /var/confd/homes/private/.ssh\n" + + " /var/confd/homes/private\n" + + " \n" + + " \n" + + " public\n" + + " 9000\n" + + " 20\n" + + " $1$lYiRxyl.$0ofHPegBlwr7asbjz/a/Q.\n" + + " /var/confd/homes/public/.ssh\n" + + " /var/confd/homes/public\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 0\n" + + " \\h>\n" + + " \n" + + " \n" + + " \n" + + " 15\n" + + " \\h#\n" + + " \n" + + " \n" + + " \n" + + " exec\n" + + " \n" + + " 0\n" + + " \n" + + " action\n" + + " \n" + + " \n" + + " autowizard\n" + + " \n" + + " \n" + + " enable\n" + + " \n" + + " \n" + + " exit\n" + + " \n" + + " \n" + + " help\n" + + " \n" + + " \n" + + " startup\n" + + " \n" + + " \n" + + " \n" + + " 15\n" + + " \n" + + " configure\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " permit\n" + + " \n" + + " \n" + + " admin\n" + + " admin\n" + + " private\n" + + " \n" + + " \n" + + " oper\n" + + " oper\n" + + " public\n" + + " \n" + + " \n" + + " \n" + + " admin\n" + + " admin\n" + + " \n" + + " any-access\n" + + " permit\n" + + " \n" + + " \n" + + " \n" + + " any-group\n" + + " *\n" + + " \n" + + " tailf-aaa-authentication\n" + + " tailf-aaa\n" + + " /aaa/authentication/users/user[name='$USER']\n" + + " read update\n" + + " permit\n" + + " \n" + + " \n" + + " tailf-aaa-user\n" + + " tailf-aaa\n" + + " /user[name='$USER']\n" + + " create read update delete\n" + + " permit\n" + + " \n" + + " \n" + + " tailf-webui-user\n" + + " tailf-webui\n" + + " /webui/data-stores/user-profile[username='$USER']\n" + + " create read update delete\n" + + " permit\n" + + " \n" + + " \n" + + " \n" + + " "; + + static final String RESPONSE_DATA1 = + "\n" + + " " + RESPONSE_BODY1 + "\n" + + ""; + + static final String ERROR_DATA2 = + "\n" + + " \n" + + " application\n" + + " invalid-value\n" + + " error\n" + + " \n" + + " /t:top/t:interface[t:name=\"Ethernet0/0\"]/t:mtu\n" + + " \n" + + " \n" + + " MTU value 25000 is not within range 256..9192\n" + + " \n" + + " \n" + + " \n" + + " application" + + " invalid-value\n" + + " error\n" + + " \n" + + " /t:top/t:interface[t:name=\"Ethernet1/0\"]/t:address/t:name\n" + + " \n" + + " \n" + + " Invalid IP address for interface Ethernet1/0\n" + + " \n" + + " \n" + + " "; + + + @Test + public void testOkParse() { + NetconfRpcReply ok = NetconfRpcParserUtil.parseRpcReply(OK_DATA1); + assertThat(ok.isOk(), is(true)); + assertThat(ok.messageId(), is("3")); + } + + @Test + public void testErrorWithAnyParse() { + + NetconfRpcReply reply = NetconfRpcParserUtil.parseRpcReply(ERROR_DATA1); + + assertThat(reply.messageId(), is("4")); + + List errs = reply.errors(); + assertThat(errs, hasSize(1)); + + NetconfRpcError err = errs.get(0); + assertThat(err.type(), is(ErrorType.APPLICATION)); + assertThat(err.tag(), is(ErrorTag.INVALID_VALUE)); + assertThat(err.severity(), is(ErrorSeverity.ERROR)); + assertThat(err.path().isPresent(), is(true)); + assertThat(err.path().get().trim(), is(ERROR_XPATH1)); + assertThat(err.message(), is(notNullValue())); + assertThat(err.message(), is("\"fastEther\" is not a valid value.")); + assertThat(err.info().get(NetconfRpcError.BAD_ELEMENT), is(endsWith("type"))); + assertThat(err.info().size(), is(1)); + assertThat(err.infoAny(), hasSize(1)); + assertThat(err.infoAny().get(0), is(instanceOf(Node.class))); + assertThat(NetconfRpcParserUtil.toString(err.infoAny().get(0)), + is(both(startsWith("")))); + + assertThat(err.appTag().isPresent(), is(false)); + } + + @Test + public void testErrorParse() { + + NetconfRpcReply reply = NetconfRpcParserUtil.parseRpcReply(ERROR_DATA2); + + assertThat(reply.messageId(), is("101")); + + List errs = reply.errors(); + assertThat(errs, hasSize(2)); + + NetconfRpcError err1 = errs.get(0); + assertThat(err1.type(), is(ErrorType.APPLICATION)); + assertThat(err1.tag(), is(ErrorTag.INVALID_VALUE)); + assertThat(err1.severity(), is(ErrorSeverity.ERROR)); + assertThat(err1.path().isPresent(), is(true)); + assertThat(err1.path().get().trim(), is("/t:top/t:interface[t:name=\"Ethernet0/0\"]/t:mtu")); + assertThat(err1.message(), is(notNullValue())); + assertThat(err1.message().trim(), is("MTU value 25000 is not within range 256..9192")); + assertThat(err1.info().size(), is(0)); + assertThat(err1.infoAny(), hasSize(0)); + assertThat(err1.appTag().isPresent(), is(false)); + + NetconfRpcError err2 = errs.get(1); + assertThat(err2.type(), is(ErrorType.APPLICATION)); + assertThat(err2.tag(), is(ErrorTag.INVALID_VALUE)); + assertThat(err2.severity(), is(ErrorSeverity.ERROR)); + assertThat(err2.path().isPresent(), is(true)); + assertThat(err2.path().get().trim(), is("/t:top/t:interface[t:name=\"Ethernet1/0\"]/t:address/t:name")); + assertThat(err2.message(), is(notNullValue())); + assertThat(err2.message().trim(), is("Invalid IP address for interface Ethernet1/0")); + assertThat(err2.info().size(), is(0)); + assertThat(err2.infoAny(), hasSize(0)); + assertThat(err2.appTag().isPresent(), is(false)); + } + + @Test + public void testGetResponseParse() { + NetconfRpcReply rep = NetconfRpcParserUtil.parseRpcReply(RESPONSE_DATA1); + assertThat(rep.isOk(), is(false)); + assertThat(rep.messageId(), is("5")); + + assertThat(rep.responses(), hasSize(1)); + assertThat(rep.responses().get(0), + is(both(startsWith("")))); + // Can't do below: response contains xmlns attribute for netconf base + //assertThat(rep.responses().get(0), is(RESPONSE_BODY1)); + } + +}