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.CmdExecutor;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 * Created by hj on 12/8/15.
18 private static Logger log = LoggerFactory.getLogger(Link.class);
19 private final Connector srcInterface;
20 private final Connector dstInterface;
22 public Link(Connector srcInterface, Connector dstInterface) {
23 this.srcInterface = srcInterface;
24 this.dstInterface = dstInterface;
27 public Connector getSrcConnector() {
31 public Connector getDstConnector() {
35 public void install() {
36 String linkAddCmd = "ip link add name " + srcInterface.getConnectorName() + " type veth peer name " + dstInterface.getConnectorName();
38 CmdExecutor.sshExecute(linkAddCmd);
39 } catch (Exception e) {
40 // TODO Auto-generated catch block
41 log.error("Exception:",e);
45 public void uninstall() {
46 String linkDelCmd = "ip link del " + srcInterface.getConnectorName();
48 CmdExecutor.sshExecute(linkDelCmd);
49 } catch (Exception e) {
50 // TODO Auto-generated catch block
51 log.error("Exception:",e);
56 public boolean equals(Object o) {
57 if (this == o) return true;
58 if (o == null || getClass() != o.getClass()) return false;
62 if (dstInterface != null ? !dstInterface.equals(link.dstInterface) : link.dstInterface != null) return false;
63 if (srcInterface != null ? !srcInterface.equals(link.srcInterface) : link.srcInterface != null) return false;
69 public int hashCode() {
70 int result = srcInterface != null ? srcInterface.hashCode() : 0;
71 result = 31 * result + (dstInterface != null ? dstInterface.hashCode() : 0);
76 public String toString() {
78 "srcInterface=" + srcInterface +
79 ", dstInterface=" + dstInterface +