Add initial nemo-tools structure and sandbox implementation.
[nemo.git] / nemo-tools / sandbox / src / main / java / org / opendaylight / nemo / tool / sandbox / models / Cache.java
1 /*
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.nemo.tool.sandbox.models;
10
11 import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 /**
17  * Created by hj on 12/8/15.
18  */
19 public class Cache extends Host {
20     public Cache(String name,String uuId) {
21         super(NodeType.CACHE,name, uuId);
22     }
23
24     @Override
25     protected List<String> generateCommands() {
26         List<String> commands = new ArrayList<String>(generateHost());
27         //TODO: host script.
28         //open route flag
29         commands.add("ip netns exec "+getName()+"echo 1 > /proc/sys/net/ipv4/ip_forward");
30         //add default route
31         if(connectors.size()>0) {
32             commands.add("ip netns exec route add default dev "+ connectors.get(0));
33         }
34         return commands;
35     }
36
37     @Override
38     public void uninstall(){
39         try {
40             CmdExecutor.sshExecute("ip netns del " + getName());
41         } catch (Exception e) {
42             e.printStackTrace();
43         }
44     }
45 }