Resolve OSGi wiring issue in TL1
Change-Id: Ic749d0739e2faa0fc913dbffa78c38af56142834
diff --git a/protocols/tl1/api/src/main/java/org/onosproject/tl1/DefaultTl1Command.java b/protocols/tl1/api/src/main/java/org/onosproject/tl1/DefaultTl1Command.java
new file mode 100644
index 0000000..2213698
--- /dev/null
+++ b/protocols/tl1/api/src/main/java/org/onosproject/tl1/DefaultTl1Command.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2017-present 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.tl1;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default implementation of a TL1 command.
+ */
+public final class DefaultTl1Command implements Tl1Command {
+ private static final char HYPHEN = '-';
+ private static final char COLON = ':';
+ private static final char SEMICOLON = ';';
+
+ private String verb;
+ private String modifier;
+ private Optional<String> tid;
+ private String aid;
+ private int ctag;
+ private String parameters;
+
+ private DefaultTl1Command(String verb, String modifier, String tid, String aid, int ctag, String parameters) {
+ this.verb = verb;
+ this.modifier = modifier;
+ this.tid = Optional.ofNullable(tid);
+ this.aid = aid;
+ this.ctag = ctag;
+ this.parameters = parameters;
+ }
+
+ @Override
+ public String verb() {
+ return verb;
+ }
+
+ @Override
+ public String modifier() {
+ return modifier;
+ }
+
+ @Override
+ public Optional<String> tid() {
+ return tid;
+ }
+
+ @Override
+ public Optional<String> aid() {
+ return Optional.ofNullable(aid);
+ }
+
+ @Override
+ public int ctag() {
+ return ctag;
+ }
+
+ @Override
+ public Optional<String> parameters() {
+ return Optional.ofNullable(parameters);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder()
+ .append(verb).append(HYPHEN)
+ .append(modifier).append(COLON)
+ .append(tid().orElse("")).append(COLON)
+ .append(aid().orElse("")).append(COLON)
+ .append(ctag);
+
+ if (parameters().isPresent()) {
+ sb.append(COLON).append(COLON).append(parameters);
+ }
+
+ return sb.append(SEMICOLON).toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements Tl1Command.Builder {
+ private String verb;
+ private String modifier;
+ private String tid;
+ private String aid;
+ private int ctag;
+ private String parameters;
+
+ @Override
+ public Tl1Command.Builder withVerb(String verb) {
+ this.verb = verb;
+ return this;
+ }
+
+ @Override
+ public Tl1Command.Builder withModifier(String modifier) {
+ this.modifier = modifier;
+ return this;
+ }
+
+ @Override
+ public Tl1Command.Builder forTid(String tid) {
+ this.tid = tid;
+ return this;
+ }
+
+ @Override
+ public Tl1Command.Builder withAid(String aid) {
+ this.aid = aid;
+ return this;
+ }
+
+ @Override
+ public Tl1Command.Builder withCtag(int ctag) {
+ this.ctag = ctag;
+ return this;
+ }
+
+ @Override
+ public Tl1Command.Builder withParameters(String parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+
+ @Override
+ public Tl1Command build() {
+ checkNotNull(verb, "Must supply a verb");
+ checkNotNull(modifier, "Must supply a modifier");
+
+ checkArgument(MIN_CTAG < ctag, "ctag cannot be less than " + MIN_CTAG);
+ checkArgument(ctag <= MAX_CTAG, "ctag cannot be larger than " + MAX_CTAG);
+
+ return new DefaultTl1Command(verb, modifier, tid, aid, ctag, parameters);
+ }
+ }
+}
diff --git a/protocols/tl1/api/src/main/java/org/onosproject/tl1/DefaultTl1Device.java b/protocols/tl1/api/src/main/java/org/onosproject/tl1/DefaultTl1Device.java
new file mode 100644
index 0000000..27ac9c9
--- /dev/null
+++ b/protocols/tl1/api/src/main/java/org/onosproject/tl1/DefaultTl1Device.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2016-present 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.tl1;
+
+import io.netty.channel.Channel;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default implementation of a TL1 device.
+ */
+public class DefaultTl1Device implements Tl1Device {
+ private final Logger log = LoggerFactory.getLogger(DefaultTl1Device.class);
+ private static final String TL1 = "tl1";
+
+ private IpAddress ip;
+ private int port;
+ private String username;
+ private String password;
+ private String tid;
+ private Channel channel;
+
+ @Override
+ public void connect(Channel channel) {
+ this.channel = channel;
+ }
+
+ @Override
+ public void disconnect() {
+ this.channel = null;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return channel != null;
+ }
+
+ @Override
+ public IpAddress ip() {
+ return ip;
+ }
+
+ @Override
+ public int port() {
+ return port;
+ }
+
+ @Override
+ public String username() {
+ return username;
+ }
+
+ @Override
+ public String password() {
+ return password;
+ }
+
+ @Override
+ public Channel channel() {
+ return channel;
+ }
+
+ @Override
+ public String tid() {
+ return tid;
+ }
+
+ public DefaultTl1Device(IpAddress ip, int port, String username, String password) {
+ this.ip = checkNotNull(ip);
+ checkArgument((TpPort.MIN_PORT <= port) && (port <= TpPort.MAX_PORT));
+ this.port = port;
+ this.username = checkNotNull(username);
+ this.password = checkNotNull(password);
+ this.tid = null;
+ channel = null;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ip, port, username, password);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultTl1Device) {
+ DefaultTl1Device that = (DefaultTl1Device) obj;
+ return Objects.equals(ip, that.ip) &&
+ Objects.equals(port, that.port) &&
+ Objects.equals(username, that.username) &&
+ Objects.equals(password, that.password) &&
+ Objects.equals(tid, that.tid) &&
+ Objects.equals(channel, that.channel);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("ip", ip)
+ .add("port", port)
+ .add("username", username)
+ .add("password", password)
+ .add("tid", tid == null ? "N/A" : tid)
+ .toString();
+ }
+}