2 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.nemo.tool.sandbox.models;
11 import org.opendaylight.nemo.tool.sandbox.utils.Config;
12 import org.opendaylight.nemo.tool.sandbox.utils.HexString;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.List;
21 * Created by hj on 12/8/15.
23 public class Switch extends Node {
24 private static Logger log = LoggerFactory.getLogger(Switch.class);
25 private final long dataPathId;
26 private final String mac;
28 public Switch(String name, long dataPathId) {
29 super(NodeType.SWITCH, name);
30 this.dataPathId = dataPathId;
32 this.mac = HexString.toHexString(dataPathId);
35 public long getDataPathId() {
40 protected List<String> generateCommands() {
41 List<String> commands = new ArrayList<String>();
43 String controllerSocket = Config.getControllerSocket();
44 String strInterface = "";
45 Collections.sort(connectors);
46 for (Connector connector : this.connectors) {
47 strInterface += ("," + connector.getConnectorName());
49 if (this.connectors.isEmpty()) {
50 log.warn("Switch {} does not have ports.");
53 strInterface = strInterface.substring(1);
55 String ofDataPathCreate = "ofdatapath";
56 if (!strInterface.equals("")) {
57 ofDataPathCreate += (" -i " + strInterface);
59 ofDataPathCreate += (" punix:/tmp/sw" + dataPathId + " -d " + mac + " 1> /tmp/sw" + dataPathId + "-ofd.log 2> /tmp/sw" + dataPathId + "-ofd.log &");
60 commands.add(ofDataPathCreate);
62 String ofProtocol = "ofprotocol unix:/tmp/sw" + dataPathId + " tcp:" + controllerSocket + " --fail=closed 1> /tmp/sw" + dataPathId + "-ofp.log 2>/tmp/sw" + dataPathId + "-ofp.log &";
63 commands.add(ofProtocol);
64 String lldp = "dpctl unix:/tmp/sw" + dataPathId + " flow-mod cmd=add,table=0 eth_type=0x88cc apply:output=ctrl:0xff";
66 String arp = "dpctl unix:/tmp/sw" + dataPathId + " flow-mod cmd=add,table=0 eth_type=0x0806 apply:output=ctrl:0xff";
73 public String toString() {
76 ", dataPathId=" + dataPathId +
77 ", mac='" + mac + '\'' +
78 ", connectors=" + connectors +