Package ch.rakudave.jnetmap.model.IF

Examples of ch.rakudave.jnetmap.model.IF.NetworkIF


    Device d = e.getItem();
    StringBuffer sb = new StringBuffer();
    sb.append(new Date().toString()).append(" [");
    sb.append(m.getFileName()).append("] - ");
    if (Type.INTERFACE_STATUS_CHANGED.equals(e.getType())) {
      NetworkIF nif = (NetworkIF) e.getSubject();
      sb.append(nif.getName()).append(" ");
      sb.append(nif.getAddress()).append(": ");
      sb.append(nif.getStatus().getMessage());
      sb.append(" (").append(d.getName()).append(")");
    } else {
      sb.append(d.getName()).append(": ");
      sb.append(d.getStatus().getMessage());
    }
View Full Code Here


    if (!match) return;
    Device d = e.getItem();
    String icon = new File(IO.userDir, "cisco/"+d.getType().toString().toLowerCase()+".png").getAbsolutePath();
    StringBuffer sb = new StringBuffer();
    if (Type.INTERFACE_STATUS_CHANGED.equals(e.getType())) {
      NetworkIF nif = (NetworkIF) e.getSubject();
      sb.append(nif.getName()).append(" ");
      sb.append(nif.getAddress()).append(": ");
      sb.append(nif.getStatus().getMessage());
      libnotify(new String[] {"notify-send", "-i", icon, sb.toString(), Lang.get("device")+": "+d.getName()});
    } else {
      for (Iterator<NetworkIF> it = d.getInterfaces().iterator(); it.hasNext();) {
        formatIF(sb, (NetworkIF) it.next());
        if (it.hasNext()) sb.append("\n");
View Full Code Here

    if (hosts == null || hosts.isEmpty() || map == null) return;
    // TODO devices are added at [0,0], find way to layout properly!
    Connection gToS = new Connection();
    Device gateway = null;
    Device aSwitch = null;
    NetworkIF gatewayIF = null;
    try { // try to find the gateway
      gatewayIF = tryFindIP(map, InetAddress.getByName(subnet.getInfo().getLowAddress()));
    } catch (UnknownHostException ex) {
      Logger.debug("Unable to find gateway-interface", ex);
    }
    if (gatewayIF == null) { // create a gateway if none was found
      gateway = new Host(Type.Router);
      gatewayIF = new PhysicalIF(gateway, gToS, subnet.getInfo().getLowAddress());
      map.addVertex(gateway);
      gateway.addInterface(gatewayIF);
    } else {
      gateway = gatewayIF.getDevice();
    }
    try { // try to find the switch attached to the gateway
      aSwitch = map.getOpposite(gateway, gatewayIF.getConnection());
      // if the opposite is not a switch, reset
      if (aSwitch != null && !aSwitch.getType().toString().toLowerCase().contains("switch")) aSwitch = null;
    } catch (Exception e) {
      Logger.debug("Unable to find opposite", e);
    }
    if (aSwitch == null) { // create a switch if necessary
      aSwitch = new Host(Type.Switch);
      map.addVertex(aSwitch);
      aSwitch.addInterface(new TransparentIF(aSwitch, gToS, gatewayIF));
      map.addEdge(gToS, gateway, aSwitch);
    }
    final Device gw = gateway, sw = aSwitch;
    final NetworkIF gif = gatewayIF;
    for (final InetAddress address : hosts.keySet()) {
      Scheduler.execute(new Runnable() {
        @Override
        public void run() {
          try {
            if (!address.equals(gif.getAddress())) {
              if (tryFindIP(map, address) != null) return;
              Logger.debug("Adding Interface "+address);
              Connection c = new Connection();
              Device d = new Host();
                d.setName(address.getHostName());
View Full Code Here

            && !nif.getAddress().getHostAddress().matches(ipMatcher)) return false;
        if (!subnetMatcher.isEmpty() && nif.getSubnet() != null
            && !nif.getSubnet().getInfo().getBroadcastAddress().matches(ipMatcher))  return false;
      }
    } else if (onIFChange && Type.INTERFACE_STATUS_CHANGED.equals(e.getType())) {
      NetworkIF nif = (NetworkIF) e.getSubject();
      if (!statusMatcher.isEmpty() && !nif.getStatus().getMessage().matches(statusMatcher)) return false;
      if (!ipMatcher.isEmpty() && nif.getAddress() != null
          && !nif.getAddress().getHostAddress().matches(ipMatcher)) return false;
      if (!subnetMatcher.isEmpty() && nif.getSubnet() != null
          && !nif.getSubnet().getInfo().getBroadcastAddress().matches(ipMatcher)) return false;
      return statusMatcher.isEmpty() && ipMatcher.isEmpty() && subnetMatcher.isEmpty();
    } else {
      return false;
    }
    return true;
View Full Code Here

    if (arg1.getInterfaceFor(arg0) == null) {
      if (arg1.equals(arg2)) {
        arg1.addInterface(new LogicalIF(arg1, arg0, ""));
      } else {
        String t = arg1.getType().toString() + "";
        NetworkIF nif;
        if (t.contains("Switch") || t.contains("Hub") || t.contains("Wireless")) {
          nif = new TransparentIF(arg1, arg0, arg2.getInterfaceFor(arg0));
        } else {
          nif = new PhysicalIF(arg1, arg0, "");
        }
        arg1.addInterface(nif);
        NetworkIF counterpart = arg2.getInterfaceFor(arg0);
        if (counterpart != null && counterpart instanceof TransparentIF) {
          ((TransparentIF) counterpart).setCounterpart(nif);
        }
      }
    }
View Full Code Here

      public Object redo() {
        for (Connection c : graph.getOutEdges(arg0)) {
          Pair<Device> pair = graph.getEndpoints(c);
          connectors.put(pair, c);
          Device other = (pair.getFirst().equals(arg0))?pair.getSecond():pair.getFirst();
          NetworkIF nif = other.getInterfaceFor(c);
          oppositeIFs.put(c, nif);
          other.removeInterface(nif);
        }
        boolean b = graph.removeVertex(arg0);
        notifyListeners(new MapEvent(_this, Type.VERTEX_REMOVED, arg0));
View Full Code Here

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      JLabel label = (JLabel) super.getListCellRendererComponent(list,
          value, index, isSelected, cellHasFocus);
      if (value == null) return label;
      NetworkIF nif = (NetworkIF) value;
      try {
        label.setText(nif.toString() + " -> " + Controller.getCurrentMap().getOpposite(d, nif.getConnection()));
      } catch (Exception e) {
        Logger.debug("Failed to get opposite of "+nif.toString(), e);
      }
      return label;
    }
View Full Code Here

    super(owner, Lang.getNoHTML("connection.properties"), ModalityType.DOCUMENT_MODAL);
    setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(800,350));
    setMaximumSize(new Dimension(850,400));
    Pair<Device> pair = Controller.getCurrentMap().getEndpoints(c);
    NetworkIF nif1 = pair.getFirst().getInterfaceFor(c), nif2 = pair.getSecond().getInterfaceFor(c);
    JPanel deviceNames = new JPanel(new GridLayout(1,3));
      JLabel leftDevice = new JLabel(pair.getFirst().getName(), (Type.Other.equals(pair.getFirst().getType()))?
          Icons.fromBase64(pair.getFirst().getOtherID()):Icons.getCisco(pair.getFirst().getType().toString().toLowerCase()), JLabel.CENTER);
        leftDevice.setHorizontalTextPosition(JLabel.CENTER);
        leftDevice.setVerticalTextPosition(JLabel.BOTTOM);
View Full Code Here

            return null;
          }
         
          @Override
          public Object redo() {
            NetworkIF counterpart = Controller.getCurrentMap().
              getOpposite(parent, i.getConnection()).getInterfaceFor(connection);
            if (isPhysical && !addressCheckbox.isSelected()) {
              newIF = new TransparentIF(parent, connection, counterpart);
                newIF.setName(newName);
              parent.addInterface(newIF);
View Full Code Here

TOP

Related Classes of ch.rakudave.jnetmap.model.IF.NetworkIF

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.