| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2014, 2015 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Vincent Perot - Initial API and implementation |
| 11 | * Patrick Tasse - Remove getSubField |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | package org.eclipse.tracecompass.internal.tmf.pcap.core.event; |
| 15 | |
| 16 | import org.eclipse.jdt.annotation.Nullable; |
| 17 | import org.eclipse.tracecompass.internal.pcap.core.packet.Packet; |
| 18 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; |
| 19 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; |
| 20 | |
| 21 | /** |
| 22 | * Class that represents the root node of Pcap Event Field. |
| 23 | * |
| 24 | * @author Vincent Perot |
| 25 | */ |
| 26 | public class PcapRootEventField extends TmfEventField { |
| 27 | |
| 28 | private final TmfEventField fPacketSourceField; |
| 29 | private final TmfEventField fPacketDestinationField; |
| 30 | private final TmfEventField fProtocolField; |
| 31 | private final String fSummaryString; |
| 32 | |
| 33 | /** |
| 34 | * Full constructor |
| 35 | * |
| 36 | * @param fields |
| 37 | * The list of subfields. |
| 38 | * @param packet |
| 39 | * The packet from which to take the fields from. |
| 40 | * @throws IllegalArgumentException |
| 41 | * If 'name' is null, or if 'fields' has duplicate field names. |
| 42 | */ |
| 43 | public PcapRootEventField(@Nullable ITmfEventField[] fields, Packet packet) { |
| 44 | super(ITmfEventField.ROOT_FIELD_ID, null, fields); |
| 45 | fPacketSourceField = new TmfEventField(PcapEvent.EVENT_FIELD_PACKET_SOURCE, |
| 46 | packet.getMostEcapsulatedPacket().getSourceEndpoint().toString(), null); |
| 47 | fPacketDestinationField = new TmfEventField(PcapEvent.EVENT_FIELD_PACKET_DESTINATION, |
| 48 | packet.getMostEcapsulatedPacket().getDestinationEndpoint().toString(), null); |
| 49 | fProtocolField = new TmfEventField(PcapEvent.EVENT_FIELD_PACKET_PROTOCOL, |
| 50 | packet.getMostEcapsulatedPacket().getProtocol().getShortName().toUpperCase(), null); |
| 51 | fSummaryString = packet.getGlobalSummaryString(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Copy constructor |
| 56 | * |
| 57 | * @param field |
| 58 | * the other event field |
| 59 | */ |
| 60 | public PcapRootEventField(final PcapRootEventField field) { |
| 61 | super(field); |
| 62 | fPacketSourceField = field.fPacketSourceField; |
| 63 | fPacketDestinationField = field.fPacketDestinationField; |
| 64 | fProtocolField = field.fProtocolField; |
| 65 | fSummaryString = field.fSummaryString; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public String toString() { |
| 70 | return fSummaryString; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public @Nullable ITmfEventField getField(String... path) { |
| 75 | if (path.length != 1) { |
| 76 | return super.getField(path); |
| 77 | } |
| 78 | switch (path[0]) { |
| 79 | case PcapEvent.EVENT_FIELD_PACKET_SOURCE: |
| 80 | return fPacketSourceField; |
| 81 | case PcapEvent.EVENT_FIELD_PACKET_DESTINATION: |
| 82 | return fPacketDestinationField; |
| 83 | case PcapEvent.EVENT_FIELD_PACKET_PROTOCOL: |
| 84 | return fProtocolField; |
| 85 | default: |
| 86 | return super.getField(path); |
| 87 | } |
| 88 | } |
| 89 | } |