<cliche.version>1.0-SNAPSHOT</cliche.version>
<ssh.version>262</ssh.version>
<json.version>20090211</json.version>
- <powermock.version>1.5.2</powermock.version>
</properties>
<dependencies>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-core</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<artifactId>commons-cli</artifactId>
<version>${cli.version}</version>
</dependency>
- <dependency>
- <groupId>com.googlecode.cliche</groupId>
- <artifactId>cliche</artifactId>
- <version>${cliche.version}</version>
- </dependency>
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
</dependency>
</dependencies>
- <repositories>
- <repository>
- <id>cliche</id>
- <url>https://oss.sonatype.org/content/repositories/snapshots</url>
- </repository>
- </repositories>
-
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/nemo.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/nemo.git</developerConnection>
+++ /dev/null
-/*
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.nemo.tool.sandbox;
-
-import asg.cliche.Command;
-import asg.cliche.Shell;
-import asg.cliche.ShellDependent;
-
-/**
- * Created by hj on 12/9/15.
- */
-public class Cli implements ShellDependent {
- private Shell shell;
-
- public Cli() {
-
- }
-
- @Override
- public void cliSetShell(Shell shell) {
- this.shell = shell;
- }
-
- @Command
- public void install() {
- SandBoxManager.getInstance().createNetwork();
- }
-
- @Command
- public void uninstall() {
- SandBoxManager.getInstance().destroyNetwork();
- }
-}
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by hj on 12/9/15.
return true;
}
} catch (IOException objException) {
-// objException.printStackTrace();
- log.error(objException);
+ log.error("Exceptions:",objException);
if (null != sshConnection) {
sshConnection.close();
sshConnection = null;
return result;
} catch (IOException objException) {
-// objException.printStackTrace();
- log.error(objException);
+ log.error("Exceptions:",objException);
} finally {
if (null != session) {
session.close();
+++ /dev/null
-/*
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.nemo.tool.sandbox;
-
-import asg.cliche.Shell;
-import asg.cliche.ShellFactory;
-
-import java.io.IOException;
-
-/**
- * Created by hj on 12/9/15.
- */
-public class EasyCli {
- private static Logger log = LoggerFactory.getLogger(EasyCli.class);
- private Shell shell;
-
- public EasyCli(String prompt,String hint,Object handler){
- shell = ShellFactory.createConsoleShell(prompt, hint, handler);
- }
-
- public void add(Object handler){
- shell.addMainHandler(handler,"");
- }
-
- public void run(){
- try {
- shell.commandLoop();
- } catch (IOException e) {
- log.error(e);
- }
- }
-}
import org.opendaylight.nemo.tool.sandbox.northbound.RestServer;
import org.opendaylight.nemo.tool.sandbox.utils.PropertyLoader;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
/**
* Created by hj on 12/9/15.
*/
public class Main {
- public static void main(String []args){
+ public static void main(String[] args) {
PropertyLoader.loadProperties("/sandbox.properties", "sandbox.properties does not exist.");
- int northboundPort = Integer.parseInt(System.getProperty("north.port","10081"));
- String socketAddress = "http://0.0.0.0:"+northboundPort+"/";
+ int northboundPort = Integer.parseInt(System.getProperty("north.port", "10081"));
+ String socketAddress = "http://0.0.0.0:" + northboundPort + "/";
RestServer.start(socketAddress);
- EasyCli easyCli = new EasyCli("sandbox","Authorized by Ip tech, Huawei",new Cli());
- easyCli.run();
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+
+ while (true) {
+ System.out.println("Enter command to create or destroy physical network (0 to exit):");
+ System.out.println("start/stop");
+ try {
+ String s = br.readLine();
+
+ if (s.equals("start")) {
+ SandBoxManager.getInstance().createNetwork();
+ continue;
+ } else if ("stop".equals(s)) {
+ SandBoxManager.getInstance().destroyNetwork();
+ continue;
+ }
+ int i = Integer.parseInt(s);
+ if (i == 0) {
+ System.exit(0);
+ }
+ } catch (NumberFormatException nfe) {
+ System.err.println("Invalid Format!");
+ }catch (IOException io){
+ io.printStackTrace();
+ }
+ }
}
}
import java.util.ArrayList;
import java.util.List;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by hj on 12/8/15.
*/
CmdExecutor.sshExecute("ip netns del " + getName());
} catch (Exception e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
}
}
import java.util.ArrayList;
import java.util.List;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by hj on 12/8/15.
*/
CmdExecutor.sshExecute("ip netns del " + getName());
} catch (Exception e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
}
}
package org.opendaylight.nemo.tool.sandbox.models;
import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by hj on 12/8/15.
*/
CmdExecutor.sshExecute(linkAddCmd);
} catch (Exception e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
}
CmdExecutor.sshExecute(linkDelCmd);
} catch (Exception e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
}
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
/**
* Created by hj on 12/9/15.
*/
return root;
} catch (JSONException e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
return null;
}
return nodeJson;
} catch (Exception e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
return null;
}
return root;
} catch (JSONException e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
return null;
}
return root;
} catch (JSONException e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
return null;
}
root.put("link", linkArray);
} catch (JSONException e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
return null;
}
return root;
return linkNode;
} catch (JSONException e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
}
return null;
} catch (Exception e) {
log.error("Error while execute [{}].", command, name, nodeType);
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
}
}
import java.util.ArrayList;
import java.util.List;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by hj on 12/8/15.
*/
CmdExecutor.sshExecute("ip netns del " + getName());
} catch (Exception e) {
// TODO Auto-generated catch block
- log.error(e);
+ log.error("Exception:",e);
}
}
}
package org.opendaylight.nemo.tool.sandbox.utils;
import java.io.*;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by hj on 12/11/15.
*/
output.write(content);
output.close();
} catch (Exception e) {
- log.error(e);
+ log.error("Exception:",e);
}
}
}
<module>nemo-features</module>
<module>nemo-karaf</module>
<module>nemo-renderers</module>
+ <module>nemo-tools</module>
</modules>
<url>https://wiki.opendaylight.org/view/NEMO:Main</url>