@Override public boolean isV6() { return this.ethertype == EtherTypes.IPv6.shortValue(); }
public static short getEtherTypeNumberShort(String name) { if (name.matches(regexNumberString)) { return Short.valueOf(name); } for (EtherTypes type : EtherTypes.values()) { if (type.description.equalsIgnoreCase(name)) { return type.shortValue(); } } return 0; }
private Ethernet createEthernet(byte[] sourceMAC, byte[] targetMAC, ARP arp, short vlan) { Ethernet ethernet = new Ethernet(); ethernet.setSourceMACAddress(sourceMAC); ethernet.setDestinationMACAddress(targetMAC); if (vlan == 0) { ethernet.setEtherType(EtherTypes.ARP.shortValue()); ethernet.setPayload(arp); } else { IEEE8021Q dot1q = new IEEE8021Q(); dot1q.setVid(vlan); dot1q.setEtherType(EtherTypes.ARP.shortValue()); dot1q.setPayload(arp); dot1q.setCfi((byte)0); dot1q.setPcp((byte)0); ethernet.setEtherType(EtherTypes.VLANTAGGED.shortValue()); ethernet.setPayload(dot1q); } return ethernet; }
private Status validateFlow(Flow flow) { Match m = flow.getMatch(); boolean isIPEthertypeSet = m.isPresent(MatchType.DL_TYPE) && (m.getField(MatchType.DL_TYPE).getValue().equals(EtherTypes.IPv4.shortValue()) || m .getField(MatchType.DL_TYPE).getValue().equals(EtherTypes.IPv6.shortValue())); // network address check if ((m.isPresent(MatchType.NW_SRC) || m.isPresent(MatchType.NW_DST)) && !isIPEthertypeSet) { return new Status(StatusCode.NOTACCEPTABLE, "The match on network source or destination address cannot be accepted if the match " + "on proper ethertype is missing"); } // transport protocol check if (m.isPresent(MatchType.NW_PROTO) && !isIPEthertypeSet) { return new Status(StatusCode.NOTACCEPTABLE, "The match on network protocol cannot be accepted if the match on proper ethertype is missing"); } // transport ports check if ((m.isPresent(MatchType.TP_SRC) || m.isPresent(MatchType.TP_DST)) && (!isIPEthertypeSet || m.isAny(MatchType.NW_PROTO))) { return new Status( StatusCode.NOTACCEPTABLE, "The match on transport source or destination port cannot be accepted if the match on network protocol and match on IP ethertype are missing"); } return new Status(StatusCode.SUCCESS); }
InetAddress ipMask = InetAddress.getByName("255.255.255.0"); InetAddress ipMask2 = InetAddress.getByName("255.240.0.0"); short ethertype = EtherTypes.IPv4.shortValue(); short vlan = (short) 27; byte vlanPr = 3;
InetAddress ipMask = InetAddress.getByName("255.255.255.0"); InetAddress ipMask2 = InetAddress.getByName("255.0.0.0"); short ethertype = EtherTypes.IPv4.shortValue(); short vlan = (short) 27; byte vlanPr = 3;
@Override public PacketResult receiveDataPacket(RawPacket inPkt) { /* * note that this assumes that the protocol plugin will do appropriate * filtering to ensure that this only receives packets for its * container. */ if (mode == BroadcastMode.DISABLED) { return PacketResult.IGNORED; } Packet decodedPkt = this.dataPacketService.decodeDataPacket(inPkt); if (decodedPkt instanceof Ethernet) { Ethernet eth = (Ethernet) decodedPkt; // TODO: should we offer an option to not handle ARP since the // ARPHandler already does that // ignore LLDP if (eth.getEtherType() != EtherTypes.LLDP.shortValue()) { if (eth.isBroadcast()) { broadcastPacket(inPkt); } else if (eth.isMulticast()) { // TODO: for now just treat multicast as broadcast broadcastPacket(inPkt); } } } return PacketResult.KEEP_PROCESSING; }
match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue()); match.setField(MatchType.NW_DST, host.getNetworkAddress());
match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue()); match.setField(MatchType.NW_SRC, InetAddress.getByName(source.getIp())); match.setField(MatchType.NW_DST, InetAddress.getByName(dest.getIp())); match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue()); match.setField(MatchType.NW_SRC, InetAddress.getByName(destMachineIp)); match.setField(MatchType.NW_DST, InetAddress.getByName(source.getIp()));
short ethertype = EtherTypes.IPv6.shortValue(); short vlan = (short) 27; byte vlanPr = (byte) 3;
private ARP createARP(short opCode, byte[] senderMacAddress, byte[] senderIP, byte[] targetMacAddress, byte[] targetIP) { ARP arp = new ARP(); arp.setHardwareType(ARP.HW_TYPE_ETHERNET); arp.setProtocolType(EtherTypes.IPv4.shortValue()); arp.setHardwareAddressLength((byte) 6); arp.setProtocolAddressLength((byte) 4); arp.setOpCode(opCode); arp.setSenderHardwareAddress(senderMacAddress); arp.setSenderProtocolAddress(senderIP); arp.setTargetHardwareAddress(targetMacAddress); arp.setTargetProtocolAddress(targetIP); return arp; }
/** * Returns whether this match is for an IPv6 flow */ public boolean isIPv6() { return (isPresent(MatchType.DL_TYPE) && ((Short) getField(MatchType.DL_TYPE).getValue()) .equals(EtherTypes.IPv6.shortValue()) || isPresent(MatchType.NW_PROTO) && ((Byte) getField(MatchType.NW_PROTO).getValue()) .equals(IPProtocols.IPV6ICMP.byteValue()) || isPresent(MatchType.NW_SRC) && getField(MatchType.NW_SRC).getValue() instanceof Inet6Address || isPresent(MatchType.NW_DST) && getField(MatchType.NW_DST).getValue() instanceof Inet6Address); }
Ethernet ethPkt = new Ethernet(); ethPkt.setSourceMACAddress(sourceMac).setDestinationMACAddress(LLDP.LLDPMulticastMac) .setEtherType(EtherTypes.LLDP.shortValue()).setPayload(discoveryPkt);