Madan Jampani

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

Showing 31 changed files with 677 additions and 180 deletions
/*
* Copyright 2014 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.onlab.onos.cli;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.store.service.DatabaseAdminService;
import org.onlab.packet.IpAddress;
/**
* Adds a new controller cluster node.
*/
@Command(scope = "onos", name = "tablet-add",
description = "Adds a new member to tablet")
public class TabletAddCommand extends AbstractShellCommand {
@Argument(index = 0, name = "nodeId", description = "Node ID",
required = true, multiValued = false)
String nodeId = null;
// TODO context aware completer to get IP from ClusterService?
@Argument(index = 1, name = "ip", description = "Node IP address",
required = true, multiValued = false)
String ip = null;
@Argument(index = 2, name = "tcpPort", description = "Node TCP listen port",
required = false, multiValued = false)
int tcpPort = 9876;
// TODO add tablet name argument when we support multiple tablets
@Override
protected void execute() {
DatabaseAdminService service = get(DatabaseAdminService.class);
ControllerNode node = new DefaultControllerNode(new NodeId(nodeId),
IpAddress.valueOf(ip),
tcpPort);
service.addMember(node);
}
}
/*
* Copyright 2014 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.onlab.onos.cli;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.store.service.DatabaseAdminService;
import java.util.Collections;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
/**
* Lists all controller cluster nodes.
*/
@Command(scope = "onos", name = "tablet-member",
description = "Lists all member nodes")
public class TabletMemberCommand extends AbstractShellCommand {
// TODO add tablet name argument when we support multiple tablets
@Override
protected void execute() {
DatabaseAdminService service = get(DatabaseAdminService.class);
ClusterService clusterService = get(ClusterService.class);
List<ControllerNode> nodes = newArrayList(service.listMembers());
Collections.sort(nodes, Comparators.NODE_COMPARATOR);
if (outputJson()) {
print("%s", json(service, nodes));
} else {
ControllerNode self = clusterService.getLocalNode();
for (ControllerNode node : nodes) {
print("id=%s, address=%s:%s %s",
node.id(), node.ip(), node.tcpPort(),
node.equals(self) ? "*" : "");
}
}
}
// Produces JSON structure.
private JsonNode json(DatabaseAdminService service, List<ControllerNode> nodes) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (ControllerNode node : nodes) {
result.add(mapper.createObjectNode()
.put("id", node.id().toString())
.put("ip", node.ip().toString())
.put("tcpPort", node.tcpPort()));
}
return result;
}
}
/*
* Copyright 2014 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.onlab.onos.cli;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.store.service.DatabaseAdminService;
/**
* Removes a controller cluster node.
*/
@Command(scope = "onos", name = "tablet-remove",
description = "Removes a member from tablet")
public class TabletRemoveCommand extends AbstractShellCommand {
@Argument(index = 0, name = "nodeId", description = "Node ID",
required = true, multiValued = false)
String nodeId = null;
// TODO add tablet name argument when we support multiple tablets
@Override
protected void execute() {
DatabaseAdminService service = get(DatabaseAdminService.class);
ClusterService clusterService = get(ClusterService.class);
ControllerNode node = clusterService.getNode(new NodeId(nodeId));
if (node != null) {
service.removeMember(node);
}
}
}
......@@ -20,6 +20,26 @@
<action class="org.onlab.onos.cli.SummaryCommand"/>
</command>
<command>
<action class="org.onlab.onos.cli.TabletMemberCommand"/>
</command>
<command>
<action class="org.onlab.onos.cli.TabletAddCommand"/>
<completers>
<ref component-id="nodeIdCompleter"/>
<null/>
<null/>
</completers>
</command>
<command>
<action class="org.onlab.onos.cli.TabletRemoveCommand"/>
<completers>
<ref component-id="nodeIdCompleter"/>
<null/>
<null/>
</completers>
</command>
<command>
<action class="org.onlab.onos.cli.NodesListCommand"/>
</command>
<command>
......
package org.onlab.onos.store.service;
import java.util.Collection;
import java.util.List;
import org.onlab.onos.cluster.ControllerNode;
/**
* Service interface for running administrative tasks on a Database.
*/
......@@ -32,4 +35,26 @@ public interface DatabaseAdminService {
* Deletes all tables from the database.
*/
public void dropAllTables();
/**
* Add member to default Tablet.
*
* @param node to add
*/
public void addMember(ControllerNode node);
/**
* Remove member from default Tablet.
*
* @param node node to remove
*/
public void removeMember(ControllerNode node);
/**
* List members forming default Tablet.
*
* @return Copied collection of members forming default Tablet.
*/
public Collection<ControllerNode> listMembers();
}
......
/*
* Copyright 2014 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.
*/
/**
* Definitions of events and messages pertaining to replication of flow entries.
*/
package org.onlab.onos.store.flow;
......@@ -17,6 +17,7 @@ package org.onlab.onos.store.hz;
import com.hazelcast.config.Config;
import com.hazelcast.config.FileSystemXmlConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
......@@ -46,6 +47,13 @@ public class StoreManager implements StoreService {
public void activate() {
try {
Config config = new FileSystemXmlConfig(HAZELCAST_XML_FILE);
MapConfig roles = config.getMapConfig("nodeRoles");
roles.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - roles.getBackupCount());
MapConfig terms = config.getMapConfig("terms");
terms.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - terms.getBackupCount());
instance = Hazelcast.newHazelcastInstance(config);
log.info("Started");
} catch (FileNotFoundException e) {
......
/*
* Copyright 2014 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.
*/
/**
* Implementation of distributed intent store.
*/
package org.onlab.onos.store.intent.impl;
/*
* Copyright 2014 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.
*/
/**
* Cluster messaging and distributed store serializers.
*/
package org.onlab.onos.store.serializers.impl;
......@@ -169,7 +169,9 @@ public class ClusterMessagingProtocol
@Override
public ProtocolClient createClient(TcpMember member) {
ControllerNode remoteNode = getControllerNode(member.host(), member.port());
checkNotNull(remoteNode, "A valid controller node is expected");
checkNotNull(remoteNode,
"A valid controller node is expected for %s:%s",
member.host(), member.port());
return new ClusterMessagingProtocolClient(
clusterCommunicator, clusterService.getLocalNode(), remoteNode);
}
......
package org.onlab.onos.store.service.impl;
import java.util.Arrays;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import net.kuujo.copycat.protocol.Response.Status;
import net.kuujo.copycat.protocol.SubmitRequest;
import net.kuujo.copycat.protocol.SubmitResponse;
import net.kuujo.copycat.spi.protocol.ProtocolClient;
import net.kuujo.copycat.Copycat;
import org.onlab.onos.store.service.DatabaseException;
import org.onlab.onos.store.service.ReadRequest;
......@@ -20,31 +17,17 @@ import org.onlab.onos.store.service.WriteRequest;
*/
public class DatabaseClient {
private final ProtocolClient client;
public DatabaseClient(ProtocolClient client) {
this.client = client;
}
private final Copycat copycat;
private static String nextId() {
return UUID.randomUUID().toString();
public DatabaseClient(Copycat copycat) {
this.copycat = checkNotNull(copycat);
}
public boolean createTable(String tableName) {
SubmitRequest request =
new SubmitRequest(
nextId(),
"createTable",
Arrays.asList(tableName));
CompletableFuture<SubmitResponse> future = client.submit(request);
CompletableFuture<Boolean> future = copycat.submit("createTable", tableName);
try {
final SubmitResponse submitResponse = future.get();
if (submitResponse.status() == Status.OK) {
return (boolean) submitResponse.result();
} else {
throw new DatabaseException(submitResponse.error());
}
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new DatabaseException(e);
}
......@@ -52,17 +35,9 @@ public class DatabaseClient {
public void dropTable(String tableName) {
SubmitRequest request =
new SubmitRequest(
nextId(),
"dropTable",
Arrays.asList(tableName));
CompletableFuture<SubmitResponse> future = client.submit(request);
CompletableFuture<Void> future = copycat.submit("dropTable", tableName);
try {
if (future.get().status() != Status.OK) {
throw new DatabaseException(future.get().toString());
}
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new DatabaseException(e);
}
......@@ -70,79 +45,39 @@ public class DatabaseClient {
public void dropAllTables() {
SubmitRequest request =
new SubmitRequest(
nextId(),
"dropAllTables",
Arrays.asList());
CompletableFuture<SubmitResponse> future = client.submit(request);
CompletableFuture<Void> future = copycat.submit("dropAllTables");
try {
if (future.get().status() != Status.OK) {
throw new DatabaseException(future.get().toString());
}
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new DatabaseException(e);
}
}
@SuppressWarnings("unchecked")
public List<String> listTables() {
SubmitRequest request =
new SubmitRequest(
nextId(),
"listTables",
Arrays.asList());
CompletableFuture<SubmitResponse> future = client.submit(request);
CompletableFuture<List<String>> future = copycat.submit("listTables");
try {
final SubmitResponse submitResponse = future.get();
if (submitResponse.status() == Status.OK) {
return (List<String>) submitResponse.result();
} else {
throw new DatabaseException(submitResponse.error());
}
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new DatabaseException(e);
}
}
@SuppressWarnings("unchecked")
public List<InternalReadResult> batchRead(List<ReadRequest> requests) {
SubmitRequest request = new SubmitRequest(
nextId(),
"read",
Arrays.asList(requests));
CompletableFuture<SubmitResponse> future = client.submit(request);
CompletableFuture<List<InternalReadResult>> future = copycat.submit("read", requests);
try {
final SubmitResponse submitResponse = future.get();
if (submitResponse.status() == Status.OK) {
return (List<InternalReadResult>) submitResponse.result();
} else {
throw new DatabaseException(submitResponse.error());
}
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new DatabaseException(e);
}
}
@SuppressWarnings("unchecked")
public List<InternalWriteResult> batchWrite(List<WriteRequest> requests) {
SubmitRequest request = new SubmitRequest(
nextId(),
"write",
Arrays.asList(requests));
CompletableFuture<SubmitResponse> future = client.submit(request);
CompletableFuture<List<InternalWriteResult>> future = copycat.submit("write", requests);
try {
final SubmitResponse submitResponse = future.get();
if (submitResponse.status() == Status.OK) {
return (List<InternalWriteResult>) submitResponse.result();
} else {
throw new DatabaseException(submitResponse.error());
}
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new DatabaseException(e);
}
......
/*
* Copyright 2014 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.onlab.onos.store.service.impl;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.NodeId;
import org.onlab.packet.IpAddress;
import org.slf4j.Logger;
import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* Allows for reading and writing tablet definition as a JSON file.
*/
public class TabletDefinitionStore {
private final Logger log = getLogger(getClass());
private final File file;
/**
* Creates a reader/writer of the tablet definition file.
*
* @param filePath location of the definition file
*/
public TabletDefinitionStore(String filePath) {
file = new File(filePath);
}
/**
* Creates a reader/writer of the tablet definition file.
*
* @param filePath location of the definition file
*/
public TabletDefinitionStore(File filePath) {
file = checkNotNull(filePath);
}
/**
* Returns the Map from tablet name to set of initial member nodes.
*
* @return Map from tablet name to set of initial member nodes
* @throws IOException when I/O exception of some sort has occurred.
*/
public Map<String, Set<DefaultControllerNode>> read() throws IOException {
final Map<String, Set<DefaultControllerNode>> tablets = new HashMap<>();
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode tabletNodes = (ObjectNode) mapper.readTree(file);
final Iterator<Entry<String, JsonNode>> fields = tabletNodes.fields();
while (fields.hasNext()) {
final Entry<String, JsonNode> next = fields.next();
final Set<DefaultControllerNode> nodes = new HashSet<>();
final Iterator<JsonNode> elements = next.getValue().elements();
while (elements.hasNext()) {
ObjectNode nodeDef = (ObjectNode) elements.next();
nodes.add(new DefaultControllerNode(new NodeId(nodeDef.get("id").asText()),
IpAddress.valueOf(nodeDef.get("ip").asText()),
nodeDef.get("tcpPort").asInt(9876)));
}
tablets.put(next.getKey(), nodes);
}
return tablets;
}
/**
* Updates the Map from tablet name to set of member nodes.
*
* @param tabletName name of the tablet to update
* @param nodes set of initial member nodes
* @throws IOException when I/O exception of some sort has occurred.
*/
public void write(String tabletName, Set<DefaultControllerNode> nodes) throws IOException {
checkNotNull(tabletName);
checkArgument(tabletName.isEmpty(), "Tablet name cannot be empty");
// TODO should validate if tabletName is allowed in JSON
// load current
Map<String, Set<DefaultControllerNode>> config;
try {
config = read();
} catch (IOException e) {
log.info("Reading tablet config failed, assuming empty definition.");
config = new HashMap<>();
}
// update with specified
config.put(tabletName, nodes);
// write back to file
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode tabletNodes = mapper.createObjectNode();
for (Entry<String, Set<DefaultControllerNode>> tablet : config.entrySet()) {
ArrayNode nodeDefs = mapper.createArrayNode();
tabletNodes.set(tablet.getKey(), nodeDefs);
for (DefaultControllerNode node : tablet.getValue()) {
ObjectNode nodeDef = mapper.createObjectNode();
nodeDef.put("id", node.id().toString())
.put("ip", node.ip().toString())
.put("tcpPort", node.tcpPort());
nodeDefs.add(nodeDef);
}
}
mapper.writeTree(new JsonFactory().createGenerator(file, JsonEncoding.UTF8),
tabletNodes);
}
}
......@@ -61,7 +61,13 @@
<group>
<title>Core Subsystems</title>
<packages>
org.onlab.onos.impl:org.onlab.onos.cluster.impl:org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.store.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.event.impl:org.onlab.onos.store.*:org.onlab.onos.net.intent.impl:org.onlab.onos.net.proxyarp.impl:org.onlab.onos.mastership.impl:org.onlab.onos.json:org.onlab.onos.json.*:org.onlab.onos.provider.host.impl:org.onlab.onos.provider.lldp.impl:org.onlab.onos.net.statistic.impl
org.onlab.onos.impl:org.onlab.onos.core.impl:org.onlab.onos.cluster.impl:org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.net.*.impl:org.onlab.onos.event.impl:org.onlab.onos.net.intent.impl:org.onlab.onos.net.proxyarp.impl:org.onlab.onos.mastership.impl:org.onlab.onos.net.resource.impl:org.onlab.onos.json:org.onlab.onos.json.*:org.onlab.onos.provider.host.impl:org.onlab.onos.provider.lldp.impl:org.onlab.onos.net.statistic.impl
</packages>
</group>
<group>
<title>Distributed Stores</title>
<packages>
org.onlab.onos.store.*
</packages>
</group>
<group>
......@@ -92,12 +98,11 @@
<group>
<title>Test Instrumentation</title>
<packages>
org.onlab.onos.metrics.*:org.onlab.onos.oecfg
org.onlab.onos.metrics.*
</packages>
</group>
</groups>
<excludePackageNames>org.onlab.thirdparty
</excludePackageNames>
<excludePackageNames>org.onlab.thirdparty:org.onlab.onos.oecfg</excludePackageNames>
</configuration>
</plugin>
</plugins>
......
onos-config command will copy files contained in this directory to ONOS instances according to cell definition
......@@ -25,3 +25,18 @@ ssh $remote "
>> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/system.properties
"
scp -q $CDEF_FILE $remote:$ONOS_INSTALL_DIR/config/
# Generate a default tablets.json from the ON* environment variables
TDEF_FILE=/tmp/tablets.json
echo "{ \"default\":[" > $TDEF_FILE
for node in $(env | sort | egrep "OC[2-9]+" | cut -d= -f2); do
echo " { \"id\": \"$node\", \"ip\": \"$node\", \"tcpPort\": 9876 }," >> $TDEF_FILE
done
echo " { \"id\": \"$OC1\", \"ip\": \"$OC1\", \"tcpPort\": 9876 }" >> $TDEF_FILE
echo "]}" >> $TDEF_FILE
scp -q $TDEF_FILE $remote:$ONOS_INSTALL_DIR/config/
# copy tools/package/config/ to remote
scp -qr ${ONOS_ROOT}/tools/package/config/ $remote:$ONOS_INSTALL_DIR/
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.api;
package org.onlab.util;
/**
* Represents condition where an item is not found or not available.
......
......@@ -17,7 +17,7 @@ package org.onlab.onos.rest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.api.ItemNotFoundException;
import org.onlab.util.ItemNotFoundException;
import org.onlab.onos.codec.CodecContext;
import org.onlab.onos.codec.CodecService;
import org.onlab.onos.codec.JsonCodec;
......@@ -69,7 +69,7 @@ public class AbstractWebResource extends BaseResource implements CodecContext {
* @param message not found message
* @param <T> item type
* @return item if not null
* @throws org.onlab.api.ItemNotFoundException if item is null
* @throws org.onlab.util.ItemNotFoundException if item is null
*/
protected <T> T nullIsNotFound(T item, String message) {
if (item == null) {
......
......@@ -15,7 +15,7 @@
*/
package org.onlab.onos.rest.exceptions;
import org.onlab.api.ItemNotFoundException;
import org.onlab.util.ItemNotFoundException;
import javax.ws.rs.core.Response;
......
This diff is collapsed. Click to expand it.
{
"event": "updateLink",
"payload": {
"id": "of:0000ffffffff0003/21-of:0000ffffffff0008/20",
"type": "direct",
"linkWidth": 6,
"src": "of:0000ffffffff0003",
"srcPort": "21",
"dst": "of:0000ffffffff0008",
"dstPort": "20",
"props" : {
"BW": "512 Gb"
}
}
}
{
"event": "updateLink",
"payload": {
"id": "of:0000ffffffff0003/21-of:0000ffffffff0008/20",
"type": "direct",
"linkWidth": 2,
"src": "of:0000ffffffff0003",
"srcPort": "21",
"dst": "of:0000ffffffff0008",
"dstPort": "20",
"props" : {
"BW": "80 Gb"
}
}
}
{
"event": "removeLink",
"payload": {
"id": "of:0000ffffffff0003/21-of:0000ffffffff0008/20",
"type": "direct",
"linkWidth": 2,
"src": "of:0000ffffffff0003",
"srcPort": "21",
"dst": "of:0000ffffffff0008",
"dstPort": "20",
"props" : {
"BW": "80 Gb"
}
}
}
......@@ -11,8 +11,8 @@
""
],
"metaUi": {
"x": 400,
"y": 280
"x": 520,
"y": 350
}
}
}
......
......@@ -11,8 +11,8 @@
""
],
"metaUi": {
"x": 400,
"y": 280
"x": 520,
"y": 350
}
}
}
......
......@@ -9,7 +9,7 @@
"dst": "of:0000ffffffff0008",
"dstPort": "20",
"props" : {
"BW": "70 G"
"BW": "70 Gb"
}
}
}
......
......@@ -10,13 +10,16 @@
"description": [
"1. add device [8] (offline)",
"2. add device [3] (offline)",
"3. update device [8] (online)",
"4. update device [3] (online)",
"3. update device [8] (online, label3 change)",
"4. update device [3] (online, label3 change)",
"5. add link [3] --> [8]",
"6. add host (to [3])",
"7. add host (to [8])",
"8. update host[3] (IP now 10.0.0.13)",
"9. update host[8] (IP now 10.0.0.17)",
"10. update link (increase width, update props)",
"11. update link (reduce width, update props)",
"12. remove link",
""
]
}
\ No newline at end of file
......
......@@ -260,36 +260,6 @@
bgImg.style('visibility', (vis === 'hidden') ? 'visible' : 'hidden');
}
function updateDeviceLabel(d) {
var label = niceLabel(deviceLabel(d)),
node = d.el,
box;
node.select('text')
.text(label)
.style('opacity', 0)
.transition()
.style('opacity', 1);
box = adjustRectToFitText(node);
node.select('rect')
.transition()
.attr(box);
node.select('image')
.transition()
.attr('x', box.x + config.icons.xoff)
.attr('y', box.y + config.icons.yoff);
}
function updateHostLabel(d) {
var label = hostLabel(d),
host = d.el;
host.select('text').text(label);
}
function cycleLabels() {
deviceLabelIndex = (deviceLabelIndex === network.deviceLabelCount - 1)
? 0 : deviceLabelIndex + 1;
......@@ -371,10 +341,10 @@
addLink: addLink,
addHost: addHost,
updateDevice: updateDevice,
updateLink: stillToImplement,
updateLink: updateLink,
updateHost: updateHost,
removeDevice: stillToImplement,
removeLink: stillToImplement,
removeLink: removeLink,
removeHost: stillToImplement,
showPath: showPath
};
......@@ -429,6 +399,18 @@
}
}
function updateLink(data) {
var link = data.payload,
id = link.id,
linkData = network.lookup[id];
if (linkData) {
$.extend(linkData, link);
updateLinkState(linkData);
} else {
logicError('updateLink lookup fail. ID = "' + id + '"');
}
}
function updateHost(data) {
var host = data.payload,
id = host.id,
......@@ -441,6 +423,17 @@
}
}
function removeLink(data) {
var link = data.payload,
id = link.id,
linkData = network.lookup[id];
if (linkData) {
removeLinkElement(linkData);
} else {
logicError('removeLink lookup fail. ID = "' + id + '"');
}
}
function showPath(data) {
var links = data.payload.links,
s = [ data.event + "\n" + links.length ];
......@@ -483,74 +476,81 @@
return 'translate(' + x + ',' + y + ')';
}
function missMsg(what, id) {
return '\n[' + what + '] "' + id + '" missing ';
}
function linkEndPoints(srcId, dstId) {
var srcNode = network.lookup[srcId],
dstNode = network.lookup[dstId],
sMiss = !srcNode ? missMsg('src', srcId) : '',
dMiss = !dstNode ? missMsg('dst', dstId) : '';
if (sMiss || dMiss) {
logicError('Node(s) not on map for link:\n' + sMiss + dMiss);
return null;
}
return {
source: srcNode,
target: dstNode,
x1: srcNode.x,
y1: srcNode.y,
x2: dstNode.x,
y2: dstNode.y
};
}
function createHostLink(host) {
var src = host.id,
dst = host.cp.device,
id = host.ingress,
srcNode = network.lookup[src],
dstNode = network.lookup[dst],
lnk;
lnk = linkEndPoints(src, dst);
if (!dstNode) {
logicError('switch not on map for link\n\n' +
'src = ' + src + '\ndst = ' + dst);
if (!lnk) {
return null;
}
// Compose link ...
lnk = {
// Synthesize link ...
$.extend(lnk, {
id: id,
source: srcNode,
target: dstNode,
class: 'link',
type: 'hostLink',
svgClass: 'link hostLink',
x1: srcNode.x,
y1: srcNode.y,
x2: dstNode.x,
y2: dstNode.y,
width: 1
}
linkWidth: 1
});
return lnk;
}
function createLink(link) {
// start with the link object as is
var lnk = link,
type = link.type,
src = link.src,
dst = link.dst,
w = link.linkWidth,
srcNode = network.lookup[src],
dstNode = network.lookup[dst];
if (!(srcNode && dstNode)) {
logicError('nodes not on map for link\n\n' +
'src = ' + src + '\ndst = ' + dst);
var lnk = linkEndPoints(link.src, link.dst),
type = link.type;
if (!lnk) {
return null;
}
// Augment as needed...
$.extend(lnk, {
source: srcNode,
target: dstNode,
// merge in remaining data
$.extend(lnk, link, {
class: 'link',
svgClass: type ? 'link ' + type : 'link',
x1: srcNode.x,
y1: srcNode.y,
x2: dstNode.x,
y2: dstNode.y,
width: w
svgClass: type ? 'link ' + type : 'link'
});
return lnk;
}
function linkWidth(w) {
// w is number of links between nodes. Scale appropriately.
// TODO: use a d3.scale (linear, log, ... ?)
return w * 1.2;
var widthRatio = 1.4,
linkScale = d3.scale.linear()
.domain([1, 12])
.range([widthRatio, 12 * widthRatio])
.clamp(true);
function updateLinkWidth (d) {
// TODO: watch out for .showPath/.showTraffic classes
d.el.transition()
.duration(1000)
.attr('stroke-width', linkScale(d.linkWidth));
}
function updateLinks() {
link = linkG.selectAll('.link')
.data(network.links, function (d) { return d.id; });
......@@ -572,7 +572,7 @@
})
.transition().duration(1000)
.attr({
'stroke-width': function (d) { return linkWidth(d.width); },
'stroke-width': function (d) { return linkScale(d.linkWidth); },
stroke: '#666' // TODO: remove explicit stroke, rather...
});
......@@ -589,13 +589,20 @@
//link .foo() .bar() ...
// operate on exiting links:
// TODO: figure out how to remove the node 'g' AND its children
// TODO: better transition (longer as a dashed, grey line)
link.exit()
.attr({
'stroke-dasharray': '3, 3'
})
.style('opacity', 0.4)
.transition()
.duration(750)
.duration(2000)
.attr({
opacity: 0
'stroke-dasharray': '3, 12'
})
.transition()
.duration(1000)
.style('opacity', 0.0)
.remove();
}
......@@ -650,7 +657,6 @@
node.y = y || network.view.height() / 2;
}
function iconUrl(d) {
return 'img/' + d.type + '.png';
}
......@@ -694,12 +700,48 @@
return (label && label.trim()) ? label : '.';
}
function updateDeviceLabel(d) {
var label = niceLabel(deviceLabel(d)),
node = d.el,
box;
node.select('text')
.text(label)
.style('opacity', 0)
.transition()
.style('opacity', 1);
box = adjustRectToFitText(node);
node.select('rect')
.transition()
.attr(box);
node.select('image')
.transition()
.attr('x', box.x + config.icons.xoff)
.attr('y', box.y + config.icons.yoff);
}
function updateHostLabel(d) {
var label = hostLabel(d),
host = d.el;
host.select('text').text(label);
}
function updateDeviceState(nodeData) {
nodeData.el.classed('online', nodeData.online);
updateDeviceLabel(nodeData);
// TODO: review what else might need to be updated
}
function updateLinkState(linkData) {
updateLinkWidth(linkData);
// TODO: review what else might need to be updated
// update label, if showing
}
function updateHostState(hostData) {
updateHostLabel(hostData);
// TODO: review what else might need to be updated
......@@ -826,6 +868,25 @@
.remove();
}
function find(id, array) {
for (var idx = 0, n = array.length; idx < n; idx++) {
if (array[idx].id === id) {
return idx;
}
}
return -1;
}
function removeLinkElement(linkData) {
// remove from lookup cache
delete network.lookup[linkData.id];
// remove from links array
var idx = find(linkData.id, network.links);
network.links.splice(linkData.index, 1);
// remove from SVG
updateLinks();
}
function tick() {
node.attr({
......
......@@ -132,7 +132,7 @@
com.fasterxml.jackson.databind.node,
com.google.common.base.*,
org.eclipse.jetty.websocket.*,
org.onlab.api.*,
org.onlab.util.*,
org.onlab.osgi.*,
org.onlab.packet.*,
org.onlab.rest.*,
......