Search in sources :

Example 1 with MacAddress

use of org.netxms.base.MacAddress in project netxms by netxms.

the class FindMacAddress method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    EnterMacAddressDlg dlg = new EnterMacAddressDlg(window.getShell());
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final MacAddress macAddr = dlg.getMacAddress();
    new ConsoleJob(String.format(Messages.get().FindMacAddress_JobTitle, macAddr), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final ConnectionPoint cp = session.findConnectionPoint(macAddr);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    HostSearchResults.showConnection(cp);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().FindMacAddress_JobError, macAddr);
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) EnterMacAddressDlg(org.netxms.ui.eclipse.topology.dialogs.EnterMacAddressDlg) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) MacAddress(org.netxms.base.MacAddress) ConnectionPoint(org.netxms.client.topology.ConnectionPoint)

Example 2 with MacAddress

use of org.netxms.base.MacAddress in project netxms by netxms.

the class MacAddressTest method testMacAddress.

public void testMacAddress() throws Exception {
    MacAddress a1 = new MacAddress();
    assertEquals("00:00:00:00:00:00", a1.toString());
    MacAddress a2 = new MacAddress(new byte[] { 0x02, 0x0C, (byte) 0xD4, 0x55, 0x22, 0x1A });
    assertEquals("02:0C:D4:55:22:1A", a2.toString());
    MacAddress a3 = MacAddress.parseMacAddress("02:0C:D4:55:22:1A");
    assertEquals(a2, a3);
    MacAddress a4 = MacAddress.parseMacAddress("020.CD4.552.21A");
    assertEquals(a2, a4);
    assertEquals("02:0C:D4:55:22:1A", a4.toString());
    try {
        MacAddress.parseMacAddress("bad mac string");
        assertTrue(false);
    } catch (MacAddressFormatException e) {
        System.out.println("Exception caught: " + e.getMessage());
    }
}
Also used : MacAddressFormatException(org.netxms.base.MacAddressFormatException) MacAddress(org.netxms.base.MacAddress)

Example 3 with MacAddress

use of org.netxms.base.MacAddress in project netxms by netxms.

the class CreateInterfaceDialog method okPressed.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
@Override
protected void okPressed() {
    physicalPort = checkIsPhy.getSelection();
    if (!WidgetHelper.validateTextInput(nameField, new ObjectNameValidator(), null) || !WidgetHelper.validateTextInput(macAddrField, new MacAddressValidator(true), null) || !WidgetHelper.validateTextInput(ipAddrField, new IPAddressValidator(true), null) || !WidgetHelper.validateTextInput(ipMaskField, new IPNetMaskValidator(true), null) || (physicalPort && !WidgetHelper.validateTextInput(slotField, new NumericTextFieldValidator(0, 4096), null)) || (physicalPort && !WidgetHelper.validateTextInput(portField, new NumericTextFieldValidator(0, 4096), null)))
        return;
    try {
        name = nameField.getText().trim();
        macAddress = macAddrField.getText().trim().isEmpty() ? new MacAddress() : MacAddress.parseMacAddress(macAddrField.getText());
        // $NON-NLS-1$
        InetAddress addr = ipAddrField.getText().trim().isEmpty() ? InetAddress.getByName("0.0.0.0") : InetAddress.getByName(ipAddrField.getText());
        ipAddress = new InetAddressEx(addr, getMaskBits(ipMaskField.getText().trim(), addr instanceof Inet4Address ? 32 : 128));
        slot = physicalPort ? Integer.parseInt(slotField.getText()) : 0;
        port = physicalPort ? Integer.parseInt(portField.getText()) : 0;
        super.okPressed();
    } catch (Exception e) {
        // $NON-NLS-1$
        MessageDialogHelper.openError(getShell(), Messages.get().CreateInterfaceDialog_Error, String.format("Internal error: %s", e.getMessage()));
    }
}
Also used : MacAddressValidator(org.netxms.ui.eclipse.tools.MacAddressValidator) IPAddressValidator(org.netxms.ui.eclipse.tools.IPAddressValidator) ObjectNameValidator(org.netxms.ui.eclipse.tools.ObjectNameValidator) NumericTextFieldValidator(org.netxms.ui.eclipse.tools.NumericTextFieldValidator) Inet4Address(java.net.Inet4Address) IPNetMaskValidator(org.netxms.ui.eclipse.tools.IPNetMaskValidator) InetAddressEx(org.netxms.base.InetAddressEx) MacAddress(org.netxms.base.MacAddress) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException)

Aggregations

MacAddress (org.netxms.base.MacAddress)3 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 InetAddressEx (org.netxms.base.InetAddressEx)1 MacAddressFormatException (org.netxms.base.MacAddressFormatException)1 NXCSession (org.netxms.client.NXCSession)1 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 IPAddressValidator (org.netxms.ui.eclipse.tools.IPAddressValidator)1 IPNetMaskValidator (org.netxms.ui.eclipse.tools.IPNetMaskValidator)1 MacAddressValidator (org.netxms.ui.eclipse.tools.MacAddressValidator)1 NumericTextFieldValidator (org.netxms.ui.eclipse.tools.NumericTextFieldValidator)1 ObjectNameValidator (org.netxms.ui.eclipse.tools.ObjectNameValidator)1 EnterMacAddressDlg (org.netxms.ui.eclipse.topology.dialogs.EnterMacAddressDlg)1