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 static Logger log = LoggerFactory.getLogger(Link.class);
18 private final Connector srcInterface;
19 private final Connector dstInterface;
21 public Link(Connector srcInterface, Connector dstInterface) {
22 this.srcInterface = srcInterface;
23 this.dstInterface = dstInterface;
26 public Connector getSrcConnector() {
30 public Connector getDstConnector() {
34 public void install() {
35 String linkAddCmd = "ip link add name " + srcInterface.getConnectorName() + " type veth peer name " + dstInterface.getConnectorName();
37 CmdExecutor.sshExecute(linkAddCmd);
38 } catch (Exception e) {
39 // TODO Auto-generated catch block
44 public void uninstall() {
45 String linkDelCmd = "ip link del " + srcInterface.getConnectorName();
47 CmdExecutor.sshExecute(linkDelCmd);
48 } catch (Exception e) {
49 // TODO Auto-generated catch block
55 public boolean equals(Object o) {
56 if (this == o) return true;
57 if (o == null || getClass() != o.getClass()) return false;
61 if (dstInterface != null ? !dstInterface.equals(link.dstInterface) : link.dstInterface != null) return false;
62 if (srcInterface != null ? !srcInterface.equals(link.srcInterface) : link.srcInterface != null) return false;
68 public int hashCode() {
69 int result = srcInterface != null ? srcInterface.hashCode() : 0;
70 result = 31 * result + (dstInterface != null ? dstInterface.hashCode() : 0);
75 public String toString() {
77 "srcInterface=" + srcInterface +
78 ", dstInterface=" + dstInterface +