Search in sources :

Example 11 with TmfPcapProtocol

use of org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol in project tracecompass by tracecompass.

the class PcapEventTest method setUp.

/**
 * Initialize the Packet and the EventField.
 *
 * @throws TmfTraceException
 *             Thrown when the trace is not valid.
 */
@BeforeClass
public static void setUp() throws TmfTraceException {
    PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
    assumeTrue(trace.exists());
    PcapTrace pcapTrace = new PcapTrace();
    pcapTrace.initTrace(null, trace.getPath().toString(), PcapEvent.class);
    fEvent = pcapTrace.parseEvent(new TmfContext(new TmfLongLocation(3), 3));
    pcapTrace.dispose();
    // Initialize protocol list.
    List<TmfPcapProtocol> list = new ArrayList<>();
    list.add(TmfPcapProtocol.PCAP);
    list.add(TmfPcapProtocol.ETHERNET_II);
    list.add(TmfPcapProtocol.IPV4);
    list.add(TmfPcapProtocol.TCP);
    list.add(TmfPcapProtocol.UNKNOWN);
    fProtocolList = ImmutableList.copyOf(list);
}
Also used : PcapTrace(org.eclipse.tracecompass.internal.tmf.pcap.core.trace.PcapTrace) TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) TmfContext(org.eclipse.tracecompass.tmf.core.trace.TmfContext) TmfPcapProtocol(org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol) ArrayList(java.util.ArrayList) PcapTestTrace(org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace) BeforeClass(org.junit.BeforeClass)

Example 12 with TmfPcapProtocol

use of org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol in project tracecompass by tracecompass.

the class StreamListView method updateUI.

private void updateUI() {
    final Display display = Display.getDefault();
    if (display == null || display.isDisposed()) {
        return;
    }
    display.asyncExec(() -> {
        if (display.isDisposed()) {
            return;
        }
        ITmfTrace trace = fCurrentTrace;
        if (trace == null) {
            return;
        }
        StreamListAnalysis analysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, StreamListAnalysis.class, StreamListAnalysis.ID);
        if (analysis == null) {
            return;
        }
        Map<TmfPcapProtocol, Table> tables = fTableMap;
        if (tables == null) {
            return;
        }
        for (Entry<TmfPcapProtocol, Table> protocolEntry : tables.entrySet()) {
            TmfPcapProtocol protocol = protocolEntry.getKey();
            TmfPacketStreamBuilder builder = analysis.getBuilder(protocol);
            Table table = protocolEntry.getValue();
            if (builder != null && !(table.isDisposed())) {
                for (TmfPacketStream stream : builder.getStreams()) {
                    TableItem item;
                    if (stream.getID() < table.getItemCount()) {
                        item = table.getItem(stream.getID());
                    } else {
                        item = new TableItem(table, SWT.NONE);
                    }
                    item.setText(0, String.valueOf(stream.getID()));
                    item.setText(1, stream.getFirstEndpoint().toString());
                    item.setText(2, stream.getSecondEndpoint().toString());
                    item.setText(3, String.valueOf(stream.getNbPackets()));
                    item.setText(4, String.valueOf(stream.getNbBytes()));
                    item.setText(5, String.valueOf(stream.getNbPacketsAtoB()));
                    item.setText(6, String.valueOf(stream.getNbBytesAtoB()));
                    item.setText(7, String.valueOf(stream.getNbPacketsBtoA()));
                    item.setText(8, String.valueOf(stream.getNbBytesBtoA()));
                    item.setText(9, stream.getStartTime().toString());
                    item.setText(10, stream.getStopTime().toString());
                    // $NON-NLS-1$
                    item.setText(11, String.format("%.3f", stream.getDuration()));
                    // $NON-NLS-1$
                    item.setText(12, String.format("%.3f", stream.getBPSAtoB()));
                    // $NON-NLS-1$
                    item.setText(13, String.format("%.3f", stream.getBPSBtoA()));
                    item.setData(KEY_STREAM, stream);
                }
            }
        }
    });
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Table(org.eclipse.swt.widgets.Table) TmfPcapProtocol(org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol) TmfPacketStreamBuilder(org.eclipse.tracecompass.internal.tmf.pcap.core.event.TmfPacketStreamBuilder) TmfPacketStream(org.eclipse.tracecompass.internal.tmf.pcap.core.event.TmfPacketStream) TableItem(org.eclipse.swt.widgets.TableItem) StreamListAnalysis(org.eclipse.tracecompass.internal.tmf.pcap.core.analysis.StreamListAnalysis) Display(org.eclipse.swt.widgets.Display)

Example 13 with TmfPcapProtocol

use of org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol in project tracecompass by tracecompass.

the class StreamListView method createPartControl.

@Override
public void createPartControl(@Nullable Composite parent) {
    // Initialize
    final Map<TmfPcapProtocol, Table> tables = new HashMap<>();
    fTableMap = tables;
    fCurrentTrace = TmfTraceManager.getInstance().getActiveTrace();
    fCurrentStream = null;
    // Add a tab folder
    fTabFolder = new CTabFolder(parent, SWT.NONE);
    fTabFolder.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(@Nullable SelectionEvent e) {
            if (e == null) {
                return;
            }
            TmfPcapProtocol protocol = (TmfPcapProtocol) e.item.getData(KEY_PROTOCOL);
            final Table table = tables.get(protocol);
            if (table != null) {
                table.deselectAll();
            }
            fCurrentStream = null;
        }
    });
    // Add items and tables for each protocol
    for (TmfPcapProtocol protocol : TmfPcapProtocol.values()) {
        if (protocol.supportsStream()) {
            CTabItem item = new CTabItem(fTabFolder, SWT.NONE);
            item.setText(protocol.getName());
            item.setData(KEY_PROTOCOL, protocol);
            Table table = new Table(fTabFolder, SWT.NONE);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            // Add columns to table
            for (int i = 0; i < COLUMN_NAMES.length || i < COLUMN_SIZES.length; i++) {
                TableColumn column = new TableColumn(table, SWT.NONE);
                column.setText(COLUMN_NAMES[i]);
                column.setWidth(COLUMN_SIZES[i]);
            }
            item.setControl(table);
            table.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(@Nullable SelectionEvent e) {
                    if (e == null) {
                        return;
                    }
                    fCurrentStream = (TmfPacketStream) e.item.getData(KEY_STREAM);
                }
            });
            tables.put(protocol, table);
            // Add right click menu
            Menu menu = new Menu(table);
            MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
            menuItem.setText(Messages.StreamListView_FollowStream);
            menuItem.addListener(SWT.Selection, (@Nullable Event event) -> {
                TmfSignal signal = new TmfPacketStreamSelectedSignal(this, 0, fCurrentStream);
                TmfSignalManager.dispatchSignal(signal);
            });
            menuItem = new MenuItem(menu, SWT.PUSH);
            menuItem.setText(Messages.StreamListView_Clear);
            menuItem.addListener(SWT.Selection, (@Nullable Event event) -> {
                TmfSignal signal = new TmfPacketStreamSelectedSignal(this, 0, null);
                TmfSignalManager.dispatchSignal(signal);
            });
            menuItem = new MenuItem(menu, SWT.PUSH);
            menuItem.setText(Messages.StreamListView_ExtractAsFilter);
            menuItem.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(@Nullable Event event) {
                    // Generate filter.
                    ITmfFilterTreeNode filter = generateFilter();
                    // Update view and XML
                    updateFilters(filter);
                }

                private void updateFilters(@Nullable ITmfFilterTreeNode filter) {
                    if (filter == null) {
                        return;
                    }
                    // Update XML
                    List<ITmfFilterTreeNode> filters = Lists.newArrayList(FilterManager.getSavedFilters());
                    boolean newFilter = true;
                    for (ITmfFilterTreeNode savedFilter : filters) {
                        // Use toString(explicit) equality because equals() is not implemented
                        if (savedFilter.toString(true).equals(filter.toString(true))) {
                            newFilter = false;
                            break;
                        }
                    }
                    if (newFilter) {
                        filters.add(filter);
                        FilterManager.setSavedFilters(filters.toArray(new ITmfFilterTreeNode[filters.size()]));
                    }
                    // Update Filter View
                    try {
                        final IWorkbench wb = PlatformUI.getWorkbench();
                        final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
                        IViewPart view = activePage.showView(FilterView.ID);
                        FilterView filterView = (FilterView) view;
                        filterView.addFilter(filter);
                    } catch (final PartInitException e) {
                        // $NON-NLS-1$
                        TraceUtils.displayErrorMsg(Messages.StreamListView_ExtractAsFilter, "Error opening view " + FilterView.ID + e.getMessage());
                        // $NON-NLS-1$
                        Activator.logError("Error opening view " + FilterView.ID, e);
                        return;
                    }
                }

                @Nullable
                private ITmfFilterTreeNode generateFilter() {
                    TmfPacketStream stream = fCurrentStream;
                    if (stream == null) {
                        return null;
                    }
                    // First stage - root
                    String name = Messages.StreamListView_FilterName_Stream + ' ' + stream.getProtocol().getShortName() + ' ' + stream.getFirstEndpoint() + " <--> " + // $NON-NLS-1$
                    stream.getSecondEndpoint();
                    TmfFilterNode root = new TmfFilterNode(name);
                    // Second stage - and
                    TmfFilterAndNode and = new TmfFilterAndNode(root);
                    // Third stage - protocol + or
                    TmfFilterContainsNode protocolFilter = new TmfFilterContainsNode(and);
                    protocolFilter.setEventAspect(TmfBaseAspects.getContentsAspect().forField(stream.getProtocol().getName()));
                    protocolFilter.setTraceTypeId(TmfFilterAspectNode.BASE_ASPECT_ID);
                    protocolFilter.setValue(EMPTY_STRING);
                    TmfFilterOrNode or = new TmfFilterOrNode(and);
                    // Fourth stage - and
                    TmfFilterAndNode andA = new TmfFilterAndNode(or);
                    TmfFilterAndNode andB = new TmfFilterAndNode(or);
                    // Fourth stage - endpoints
                    TmfFilterContainsNode endpointAAndA = new TmfFilterContainsNode(andA);
                    endpointAAndA.setEventAspect(PcapSourceAspect.INSTANCE);
                    endpointAAndA.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointAAndA.setValue(stream.getFirstEndpoint());
                    TmfFilterContainsNode endpointBAndA = new TmfFilterContainsNode(andA);
                    endpointBAndA.setEventAspect(PcapDestinationAspect.INSTANCE);
                    endpointBAndA.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointBAndA.setValue(stream.getSecondEndpoint());
                    TmfFilterContainsNode endpointAAndB = new TmfFilterContainsNode(andB);
                    endpointAAndB.setEventAspect(PcapSourceAspect.INSTANCE);
                    endpointAAndB.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointAAndB.setValue(stream.getSecondEndpoint());
                    TmfFilterContainsNode endpointBAndB = new TmfFilterContainsNode(andB);
                    endpointBAndB.setEventAspect(PcapDestinationAspect.INSTANCE);
                    endpointBAndB.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointBAndB.setValue(stream.getFirstEndpoint());
                    return root;
                }
            });
            table.setMenu(menu);
        }
    }
    // Ask the analysis for data.
    queryAnalysis();
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) IViewPart(org.eclipse.ui.IViewPart) CTabFolder(org.eclipse.swt.custom.CTabFolder) Listener(org.eclipse.swt.widgets.Listener) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) HashMap(java.util.HashMap) TmfPacketStream(org.eclipse.tracecompass.internal.tmf.pcap.core.event.TmfPacketStream) CTabItem(org.eclipse.swt.custom.CTabItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) FilterView(org.eclipse.tracecompass.tmf.ui.views.filter.FilterView) TmfSignal(org.eclipse.tracecompass.tmf.core.signal.TmfSignal) Table(org.eclipse.swt.widgets.Table) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfPcapProtocol(org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) TableColumn(org.eclipse.swt.widgets.TableColumn) IWorkbench(org.eclipse.ui.IWorkbench) TmfPacketStreamSelectedSignal(org.eclipse.tracecompass.internal.tmf.pcap.core.signal.TmfPacketStreamSelectedSignal) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 14 with TmfPcapProtocol

use of org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol in project tracecompass by tracecompass.

the class StreamListView method resetView.

private void resetView() {
    // Stop thread if needed
    fStopThread = true;
    // Remove all content in tables
    final Display display = Display.getDefault();
    if (display == null || display.isDisposed()) {
        return;
    }
    display.asyncExec(() -> {
        if (display.isDisposed()) {
            return;
        }
        Map<TmfPcapProtocol, Table> tableMap = fTableMap;
        if (tableMap == null) {
            return;
        }
        for (Table table : tableMap.values()) {
            if (!table.isDisposed()) {
                table.removeAll();
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) TmfPcapProtocol(org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol) Display(org.eclipse.swt.widgets.Display)

Aggregations

TmfPcapProtocol (org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol)14 Nullable (org.eclipse.jdt.annotation.Nullable)8 Packet (org.eclipse.tracecompass.internal.pcap.core.packet.Packet)6 PcapProtocol (org.eclipse.tracecompass.internal.pcap.core.protocol.PcapProtocol)5 Table (org.eclipse.swt.widgets.Table)3 PcapEvent (org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEvent)3 Display (org.eclipse.swt.widgets.Display)2 StreamListAnalysis (org.eclipse.tracecompass.internal.tmf.pcap.core.analysis.StreamListAnalysis)2 TmfPacketStream (org.eclipse.tracecompass.internal.tmf.pcap.core.event.TmfPacketStream)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Menu (org.eclipse.swt.widgets.Menu)1