diff options
Diffstat (limited to 'framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc')
6 files changed, 463 insertions, 0 deletions
diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/Callback.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/Callback.java new file mode 100644 index 00000000..f7ec8b67 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/Callback.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * 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.ovsdb.rfc.jsonrpc; + +import java.util.List; + +import org.onosproject.ovsdb.rfc.message.UpdateNotification; + +/** + * The callback function interface will be used when the server send to the + * client report changes. + */ +public interface Callback { + /** + * The "update" notification is sent by the server to the client to report + * changes in tables that are being monitored following a "*monitor" + * request. + * @param updateNotification the information of the update + */ + void update(UpdateNotification updateNotification); + + /** + * The "locked" notification is provided to notify a client that it has been + * granted a lock that it had previously requested with the "lock" method. + * @param ids the locked ids + */ + void locked(List<String> ids); + + /** + * The "stolen" notification is provided to notify a client, which had + * previously obtained a lock, that another client has stolen ownership of + * that lock. + * @param ids the stolen ids + */ + void stolen(List<String> ids); + +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonReadContext.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonReadContext.java new file mode 100644 index 00000000..8033f653 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonReadContext.java @@ -0,0 +1,86 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * 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.ovsdb.rfc.jsonrpc; + +import java.util.Stack; + +/** + * Context for decode parameters. + */ +public class JsonReadContext { + private Stack<Byte> bufStack; + private boolean isStartMatch; + private int lastReadBytes; + + /** + * Constructs a JsonReadContext object. This class only need initial + * parameter value for the readToJsonNode method of JsonRpcReaderUtil + * entity. + */ + public JsonReadContext() { + bufStack = new Stack<Byte>(); + isStartMatch = false; + lastReadBytes = 0; + } + + /** + * Return bufStack. + * @return bufStack + */ + public Stack<Byte> getBufStack() { + return bufStack; + } + + /** + * Set bufStack, used for match the braces and double quotes. + * @param bufStack Stack of Byte + */ + public void setBufStack(Stack<Byte> bufStack) { + this.bufStack = bufStack; + } + + /** + * Return isStartMatch. + * @return isStartMatch + */ + public boolean isStartMatch() { + return isStartMatch; + } + + /** + * Set isStartMatch. + * @param isStartMatch mark whether the matching has started + */ + public void setStartMatch(boolean isStartMatch) { + this.isStartMatch = isStartMatch; + } + + /** + * Return lastReadBytes. + * @return lastReadBytes + */ + public int getLastReadBytes() { + return lastReadBytes; + } + + /** + * Set lastReadBytes. + * @param lastReadBytes the bytes for last decoding incomplete record + */ + public void setLastReadBytes(int lastReadBytes) { + this.lastReadBytes = lastReadBytes; + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonRpcRequest.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonRpcRequest.java new file mode 100644 index 00000000..ecff096b --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonRpcRequest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * 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.ovsdb.rfc.jsonrpc; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.Objects; + +import com.google.common.collect.Lists; + +/** + * Json Rpc Request information that include id,method,params. + */ +public class JsonRpcRequest { + + private final String id; + private final String method; + private final List<Object> params; + + /** + * JsonRpcRequest Constructor. + * @param id the id node of request information + * @param method the method node of request information + */ + public JsonRpcRequest(String id, String method) { + checkNotNull(id, "id cannot be null"); + checkNotNull(method, "method cannot be null"); + this.id = id; + this.method = method; + this.params = Lists.newArrayList(); + } + + /** + * JsonRpcRequest Constructor. + * @param id the id node of request information + * @param method the method node of request information + * @param params the params node of request information + */ + public JsonRpcRequest(String id, String method, List<Object> params) { + checkNotNull(id, "id cannot be null"); + checkNotNull(method, "method cannot be null"); + checkNotNull(params, "params cannot be null"); + this.id = id; + this.method = method; + this.params = params; + } + + /** + * Returns id. + * @return id + */ + public String getId() { + return id; + } + + /** + * Returns method. + * @return method + */ + public String getMethod() { + return method; + } + + /** + * Returns params. + * @return params + */ + public List<Object> getParams() { + return params; + } + + @Override + public int hashCode() { + return Objects.hash(id, method, params); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof JsonRpcRequest) { + final JsonRpcRequest other = (JsonRpcRequest) obj; + return Objects.equals(this.id, other.id) + && Objects.equals(this.method, other.method) + && Objects.equals(this.params, other.params); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("id", id).add("method", method) + .add("params", params).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonRpcResponse.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonRpcResponse.java new file mode 100644 index 00000000..a2f45414 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/JsonRpcResponse.java @@ -0,0 +1,122 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * 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.ovsdb.rfc.jsonrpc; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.Objects; + +import com.google.common.collect.Lists; + +/** + * Json Rpc Response information that include id,error,result. + */ +public class JsonRpcResponse { + + private final String id; + private final String error; + private final List<Object> result; + + /** + * JsonRpcResponse Constructor. + * @param id the id node of response information + */ + public JsonRpcResponse(String id) { + checkNotNull(id, "id cannot be null"); + this.id = id; + this.error = null; + this.result = Lists.newArrayList(); + } + + /** + * JsonRpcResponse Constructor. + * @param id the id node of response information + * @param error the error node of response information + */ + public JsonRpcResponse(String id, String error) { + checkNotNull(id, "id cannot be null"); + checkNotNull(error, "error cannot be null"); + this.id = id; + this.error = error; + this.result = Lists.newArrayList(); + } + + /** + * JsonRpcResponse Constructor. + * @param id the id node of response information + * @param error the error node of response information + * @param result the result node of response information + */ + public JsonRpcResponse(String id, String error, List<Object> result) { + checkNotNull(id, "id cannot be null"); + checkNotNull(error, "error cannot be null"); + checkNotNull(result, "result cannot be null"); + this.id = id; + this.error = error; + this.result = result; + } + + /** + * Returns id. + * @return id + */ + public String getId() { + return id; + } + + /** + * Returns error. + * @return error + */ + public String getError() { + return error; + } + + /** + * Returns result. + * @return result + */ + public List<Object> getResult() { + return result; + } + + @Override + public int hashCode() { + return Objects.hash(id, error, result); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof JsonRpcResponse) { + final JsonRpcResponse other = (JsonRpcResponse) obj; + return Objects.equals(this.id, other.id) + && Objects.equals(this.error, other.error) + && Objects.equals(this.result, other.result); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("id", id).add("error", error) + .add("result", result).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/OvsdbRPC.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/OvsdbRPC.java new file mode 100644 index 00000000..5d08b143 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/OvsdbRPC.java @@ -0,0 +1,74 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * 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.ovsdb.rfc.jsonrpc; + +import java.util.List; + +import org.onosproject.ovsdb.rfc.operations.Operation; +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; + +import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * The following interface describe the RPC7047's methods that are supported. + */ +public interface OvsdbRPC { + + /** + * This operation retrieves a database-schema that describes hosted database + * db-name. + * @param dbnames database name + * @return ListenableFuture of JsonNode + */ + ListenableFuture<JsonNode> getSchema(List<String> dbnames); + + /** + * The "echo" method can be used by both clients and servers to verify the + * liveness of a database connection. + * @return return info + */ + ListenableFuture<List<String>> echo(); + + /** + * The "monitor" request enables a client to replicate tables or subsets of + * tables within an OVSDB database by requesting notifications of changes to + * those tables and by receiving the complete initial state of a table or a + * subset of a table. + * @param dbSchema databse schema + * @param monitorId a id for monitor + * @return ListenableFuture of JsonNode + */ + ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema, String monitorId); + + /** + * This operation retrieves an array whose elements are the names of the + * databases that can be accessed over this management protocol connection. + * @return database names + */ + ListenableFuture<List<String>> listDbs(); + + /** + * This RPC method causes the database server to execute a series of + * operations in the specified order on a given database. + * @param dbSchema database schema + * @param operations the operations to execute + * @return result the transact result + */ + ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema, + List<Operation> operations); + +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/package-info.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/package-info.java new file mode 100644 index 00000000..7edf5b46 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/jsonrpc/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * 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. + */ + +/** + * RFC 7047 implementation. + */ +package org.onosproject.ovsdb.rfc.jsonrpc; |