Search in sources :

Example 1 with Redirect

use of org.onlab.packet.ndp.Redirect in project onos by opennetworkinglab.

the class Ethernet method toString.

/*
     * (non-Javadoc)
     *
     * @see java.lang.Object#toString(java.lang.Object)
     */
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder("\n");
    final IPacket pkt = this.getPayload();
    if (pkt instanceof ARP) {
        sb.append("arp");
    } else if (pkt instanceof MPLS) {
        sb.append("mpls");
    } else if (pkt instanceof LLDP) {
        sb.append("lldp");
    } else if (pkt instanceof ICMP) {
        sb.append("icmp");
    } else if (pkt instanceof IPv4) {
        sb.append("ip");
    } else if (pkt instanceof DHCP) {
        sb.append("dhcp");
    } else {
        // Just print the ethertype
        sb.append(String.format(HEX_PROTO, Integer.toHexString(this.getEtherType() & 0xffff)));
    }
    if (this.getQinQVID() != Ethernet.VLAN_UNTAGGED) {
        sb.append("\ndl_qinqVlan: ");
        sb.append(this.getQinQVID());
        sb.append("\ndl_qinqVlan_pcp: ");
        sb.append(this.getQinQPriorityCode());
    }
    sb.append("\ndl_vlan: ");
    if (this.getVlanID() == Ethernet.VLAN_UNTAGGED) {
        sb.append("untagged");
    } else {
        sb.append(this.getVlanID());
    }
    sb.append("\ndl_vlan_pcp: ");
    sb.append(this.getPriorityCode());
    sb.append("\ndl_src: ");
    sb.append(bytesToHex(this.getSourceMACAddress()));
    sb.append("\ndl_dst: ");
    sb.append(bytesToHex(this.getDestinationMACAddress()));
    if (pkt instanceof ARP) {
        final ARP p = (ARP) pkt;
        sb.append("\nnw_src: ");
        sb.append(IPv4.fromIPv4Address(IPv4.toIPv4Address(p.getSenderProtocolAddress())));
        sb.append("\nnw_dst: ");
        sb.append(IPv4.fromIPv4Address(IPv4.toIPv4Address(p.getTargetProtocolAddress())));
    } else if (pkt instanceof MPLS) {
        final MPLS p = (MPLS) pkt;
        sb.append("\nmpls: ");
        sb.append(this.etherType == MPLS_UNICAST ? "unicast" : "multicast");
        sb.append("\nmpls_label: ");
        sb.append(p.label);
    } else if (pkt instanceof LLDP) {
        sb.append("lldp packet");
    } else if (pkt instanceof ICMP) {
        final ICMP icmp = (ICMP) pkt;
        sb.append("\nicmp_type: ");
        sb.append(icmp.getIcmpType());
        sb.append("\nicmp_code: ");
        sb.append(icmp.getIcmpCode());
    } else if (pkt instanceof IPv4) {
        final IPv4 p = (IPv4) pkt;
        sb.append("\nnw_src: ");
        sb.append(IPv4.fromIPv4Address(p.getSourceAddress()));
        sb.append("\nnw_dst: ");
        sb.append(IPv4.fromIPv4Address(p.getDestinationAddress()));
        sb.append("\nnw_tos: ");
        sb.append(p.getDiffServ());
        sb.append("\nnw_proto: ");
        sb.append(p.getProtocol());
        IPacket payload = pkt.getPayload();
        if (payload != null) {
            if (payload instanceof TCP) {
                sb.append("\ntp_src: ");
                sb.append(((TCP) payload).getSourcePort());
                sb.append("\ntp_dst: ");
                sb.append(((TCP) payload).getDestinationPort());
            } else if (payload instanceof UDP) {
                sb.append("\ntp_src: ");
                sb.append(((UDP) payload).getSourcePort());
                sb.append("\ntp_dst: ");
                sb.append(((UDP) payload).getDestinationPort());
            } else if (payload instanceof ICMP) {
                final ICMP icmp = (ICMP) payload;
                sb.append("\nicmp_type: ");
                sb.append(icmp.getIcmpType());
                sb.append("\nicmp_code: ");
                sb.append(icmp.getIcmpCode());
            }
        }
    } else if (pkt instanceof IPv6) {
        final IPv6 ipv6 = (IPv6) pkt;
        sb.append("\nipv6_src: ");
        sb.append(Ip6Address.valueOf(ipv6.getSourceAddress()).toString());
        sb.append("\nipv6_dst: ");
        sb.append(Ip6Address.valueOf(ipv6.getDestinationAddress()).toString());
        sb.append("\nipv6_proto: ");
        sb.append(ipv6.getNextHeader());
        IPacket payload = pkt.getPayload();
        if (payload != null && payload instanceof ICMP6) {
            final ICMP6 icmp6 = (ICMP6) payload;
            sb.append("\nicmp6_type: ");
            sb.append(icmp6.getIcmpType());
            sb.append("\nicmp6_code: ");
            sb.append(icmp6.getIcmpCode());
            payload = payload.getPayload();
            if (payload != null) {
                if (payload instanceof NeighborSolicitation) {
                    final NeighborSolicitation ns = (NeighborSolicitation) payload;
                    sb.append("\nns_target_addr: ");
                    sb.append(Ip6Address.valueOf(ns.getTargetAddress()).toString());
                    ns.getOptions().forEach(option -> {
                        sb.append("\noption_type: ");
                        sb.append(option.type());
                        sb.append("\noption_data: ");
                        sb.append(bytesToHex(option.data()));
                    });
                } else if (payload instanceof NeighborAdvertisement) {
                    final NeighborAdvertisement na = (NeighborAdvertisement) payload;
                    sb.append("\nna_target_addr: ");
                    sb.append(Ip6Address.valueOf(na.getTargetAddress()).toString());
                    sb.append("\nna_solicited_flag: ");
                    sb.append(na.getSolicitedFlag());
                    sb.append("\nna_router_flag: ");
                    sb.append(na.getRouterFlag());
                    sb.append("\nna_override_flag: ");
                    sb.append(na.getOverrideFlag());
                    na.getOptions().forEach(option -> {
                        sb.append("\noption_type: ");
                        sb.append(option.type());
                        sb.append("\noption_data: ");
                        sb.append(bytesToHex(option.data()));
                    });
                } else if (payload instanceof RouterSolicitation) {
                    final RouterSolicitation rs = (RouterSolicitation) payload;
                    sb.append("\nrs");
                    rs.getOptions().forEach(option -> {
                        sb.append("\noption_type: ");
                        sb.append(option.type());
                        sb.append("\noption_data: ");
                        sb.append(bytesToHex(option.data()));
                    });
                } else if (payload instanceof RouterAdvertisement) {
                    final RouterAdvertisement ra = (RouterAdvertisement) payload;
                    sb.append("\nra_hop_limit: ");
                    sb.append(ra.getCurrentHopLimit());
                    sb.append("\nra_mflag: ");
                    sb.append(ra.getMFlag());
                    sb.append("\nra_oflag: ");
                    sb.append(ra.getOFlag());
                    sb.append("\nra_reachable_time: ");
                    sb.append(ra.getReachableTime());
                    sb.append("\nra_retransmit_time: ");
                    sb.append(ra.getRetransmitTimer());
                    sb.append("\nra_router_lifetime: ");
                    sb.append(ra.getRouterLifetime());
                    ra.getOptions().forEach(option -> {
                        sb.append("\noption_type: ");
                        sb.append(option.type());
                        sb.append("\noption_data: ");
                        sb.append(bytesToHex(option.data()));
                    });
                } else if (payload instanceof Redirect) {
                    final Redirect rd = (Redirect) payload;
                    sb.append("\nrd_target_addr: ");
                    sb.append(Ip6Address.valueOf(rd.getTargetAddress()).toString());
                    rd.getOptions().forEach(option -> {
                        sb.append("\noption_type: ");
                        sb.append(option.type());
                        sb.append("\noption_data: ");
                        sb.append(bytesToHex(option.data()));
                    });
                }
            }
        }
    } else if (pkt instanceof DHCP) {
        sb.append("\ndhcp packet");
    } else if (pkt instanceof Data) {
        sb.append("\ndata packet");
    } else if (pkt instanceof LLC) {
        sb.append("\nllc packet");
    } else if (pkt instanceof EAPOL) {
        sb.append("\neapol");
    } else if (pkt instanceof PPPoED) {
        sb.append("\npppoed packet");
    } else {
        sb.append("\nunknown packet");
    }
    return sb.toString();
}
Also used : Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) RouterAdvertisement(org.onlab.packet.ndp.RouterAdvertisement) RouterSolicitation(org.onlab.packet.ndp.RouterSolicitation) Map(java.util.Map) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PacketUtils.checkHeaderLength(org.onlab.packet.PacketUtils.checkHeaderLength) Redirect(org.onlab.packet.ndp.Redirect) PacketUtils.checkInput(org.onlab.packet.PacketUtils.checkInput) NeighborAdvertisement(org.onlab.packet.ndp.NeighborAdvertisement) ByteBuffer(java.nio.ByteBuffer) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) RouterSolicitation(org.onlab.packet.ndp.RouterSolicitation) Redirect(org.onlab.packet.ndp.Redirect) NeighborAdvertisement(org.onlab.packet.ndp.NeighborAdvertisement) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) RouterAdvertisement(org.onlab.packet.ndp.RouterAdvertisement)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteBuffer (java.nio.ByteBuffer)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 PacketUtils.checkHeaderLength (org.onlab.packet.PacketUtils.checkHeaderLength)1 PacketUtils.checkInput (org.onlab.packet.PacketUtils.checkInput)1 NeighborAdvertisement (org.onlab.packet.ndp.NeighborAdvertisement)1 NeighborSolicitation (org.onlab.packet.ndp.NeighborSolicitation)1 Redirect (org.onlab.packet.ndp.Redirect)1 RouterAdvertisement (org.onlab.packet.ndp.RouterAdvertisement)1 RouterSolicitation (org.onlab.packet.ndp.RouterSolicitation)1