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;
14 * Created by hj on 12/8/15.
17 private final Connector srcInterface;
18 private final Connector dstInterface;
20 public Link(Connector srcInterface, Connector dstInterface) {
21 this.srcInterface = srcInterface;
22 this.dstInterface = dstInterface;
25 public Connector getSrcConnector() {
29 public Connector getDstConnector() {
33 public void install() {
34 String linkAddCmd = "ip link add name " + srcInterface.getConnectorName() + " type veth peer name " + dstInterface.getConnectorName();
36 CmdExecutor.sshExecute(linkAddCmd);
37 } catch (Exception e) {
42 public void uninstall() {
43 String linkDelCmd = "ip link del " + srcInterface.getConnectorName();
45 CmdExecutor.sshExecute(linkDelCmd);
46 } catch (Exception e) {
52 public boolean equals(Object o) {
53 if (this == o) return true;
54 if (o == null || getClass() != o.getClass()) return false;
58 if (dstInterface != null ? !dstInterface.equals(link.dstInterface) : link.dstInterface != null) return false;
59 if (srcInterface != null ? !srcInterface.equals(link.srcInterface) : link.srcInterface != null) return false;
65 public int hashCode() {
66 int result = srcInterface != null ? srcInterface.hashCode() : 0;
67 result = 31 * result + (dstInterface != null ? dstInterface.hashCode() : 0);
72 public String toString() {
74 "srcInterface=" + srcInterface +
75 ", dstInterface=" + dstInterface +