@Override public String toString() { return type + "[address = " + HexEncode.bytesToHexString(address) + "]"; } }
@Override public String toString() { return type + "[address = " + HexEncode.bytesToHexString(address) + "]"; } }
@XmlElement(name = "address") public String getDlAddressString() { return HexEncode.bytesToHexString(address); }
@XmlElement(name = "address") public String getDlAddressString() { return HexEncode.bytesToHexString(address); }
@Override public String toString() { StringBuilder ret = new StringBuilder(); ret.append(this.getClass().getSimpleName()); ret.append(": ["); for (String field : hdrFieldCoordMap.keySet()) { byte[] value = hdrFieldsMap.get(field); ret.append(field); ret.append(": "); ret.append(HexEncode.bytesToHexString(value)); ret.append(", "); } ret.replace(ret.length()-2, ret.length()-1, "]"); return ret.toString(); }
private void logArpPacket(ARP pkt, NodeConnector p, short vlan) { try { log.trace("Received Arp {} with srcMac {} - srcIp {} - dstMac {} - dstIp {} - inport {} {}", ((pkt.getOpCode() == ARP.REQUEST) ? "Request" : "Reply"), HexEncode.bytesToHexString(pkt.getSenderHardwareAddress()), InetAddress.getByAddress(pkt.getSenderProtocolAddress()), HexEncode.bytesToHexString(pkt.getTargetHardwareAddress()), InetAddress.getByAddress(pkt.getTargetProtocolAddress()), p, (vlan != 0 ? "on vlan " + vlan : "")); } catch (UnknownHostException e) { log.warn("Illegal Ip Address in the ARP packet", e); } }
.append(HexEncode.bytesToHexString(tMac)) .append(", "); .append(HexEncode.bytesToHexString(sMac)) .append(", ");
protected void sendARPReply(NodeConnector p, byte[] sMAC, InetAddress sIP, byte[] tMAC, InetAddress tIP, short vlan) { byte[] senderIP = sIP.getAddress(); byte[] targetIP = tIP.getAddress(); ARP arp = createARP(ARP.REPLY, sMAC, senderIP, tMAC, targetIP); if(log.isTraceEnabled()) { log.trace("Sending Arp Reply with srcMac {} - srcIp {} - dstMac {} - dstIp {} - outport {}", HexEncode.bytesToHexString(sMAC), sIP, HexEncode.bytesToHexString(tMAC), tIP, p); } Ethernet ethernet = createEthernet(sMAC, tMAC, arp, vlan); RawPacket destPkt = this.dataPacketService.encodeDataPacket(ethernet); destPkt.setOutgoingNodeConnector(p); this.dataPacketService.transmitDataPacket(destPkt); }
private void learnNewHost(HostNodeConnector host) { IHostId id = HostIdFactory.create(host.getNetworkAddress(), host.getDataLayerAddress()); host.initArpSendCountDown(); HostNodeConnector rHost = hostsDB.putIfAbsent(id, host); if (rHost != null) { // Another host is already learned for this IP address, replace it replaceHost(id, rHost, host); } else { logger.debug("New Host Learned: MAC: {} IP: {}", HexEncode.bytesToHexString(host .getDataLayerAddressBytes()), host.getNetworkAddress().getHostAddress()); } }
private void generateAndSendReply(InetAddress sourceIP, byte[] sourceMAC, short vlan) { if (log.isTraceEnabled()) { log.trace("generateAndSendReply called with params sourceIP:{} sourceMAC:{}", sourceIP, HexEncode.bytesToHexString(sourceMAC)); log.trace( "Sending ARP Reply with src {}/{}, target {}/{} {}", new Object[] { HexEncode.bytesToHexString(sourceMAC), sourceIP, HexEncode.bytesToHexString(host.getDataLayerAddressBytes()), host.getNetworkAddress(), (vlan != 0 ? "on vlan " + vlan : "") });
@Override public void hostListener(HostNodeConnector host) { logger.debug("Received for Host: IP {}, MAC {}, {}", host.getNetworkAddress().getHostAddress(), HexEncode.bytesToHexString(host.getDataLayerAddressBytes()), host); if (hostExists(host)) { IHostId id = HostIdFactory.create(host.getNetworkAddress(), host.getDataLayerAddress()); HostNodeConnector existinghost = hostsDB.get(id); existinghost.initArpSendCountDown(); // Update the host hostsDB.put(id, existinghost); logger.debug("hostListener returned without adding the host"); return; } new NotifyHostThread(host).start(); }
private void replaceHost(IHostId id, HostNodeConnector removedHost, HostNodeConnector newHost) { // Ignore ARP messages from internal nodes NodeConnector newHostNc = newHost.getnodeConnector(); boolean newHostIsInternal = topologyManager.isInternal(newHostNc); if (newHostIsInternal) { return; } newHost.initArpSendCountDown(); if (hostsDB.replace(id, removedHost, newHost)) { logger.debug("Host move occurred: Old Host IP:{}, New Host IP: {}", removedHost.getNetworkAddress() .getHostAddress(), newHost.getNetworkAddress().getHostAddress()); logger.debug("Old Host MAC: {}, New Host MAC: {}", HexEncode.bytesToHexString(removedHost.getDataLayerAddressBytes()), HexEncode.bytesToHexString(newHost.getDataLayerAddressBytes())); // Display the Old and New HostNodeConnectors also logger.debug("Old {}, New {}", removedHost, newHost); } else { /* * Host replacement has failed, do the recovery */ hostsDB.put(id, newHost); logger.error("Host replacement failed. Overwrite the host. Replaced Host: {}, New Host: {}", removedHost, newHost); } notifyHostLearnedOrRemoved(removedHost, false); notifyHostLearnedOrRemoved(newHost, true); if (!newHost.isStaticHost()) { processPendingARPReqs(id); } }
@Override public Packet deserialize(byte[] data, int bitOffset, int size) throws PacketException { int lldpOffset = bitOffset; // LLDP start int lldpSize = size; // LLDP size if (logger.isTraceEnabled()) { logger.trace("LLDP: {} (offset {} bitsize {})", new Object[] { HexEncode.bytesToHexString(data), lldpOffset, lldpSize }); } /* * Deserialize the TLVs until we reach the end of the packet */ while (lldpSize > 0) { LLDPTLV tlv = new LLDPTLV(); tlv.deserialize(data, lldpOffset, lldpSize); if (tlv.getType() == 0 && tlv.getLength() == 0) { break; } int tlvSize = tlv.getTLVSize(); // Size of current TLV in bits lldpOffset += tlvSize; lldpSize -= tlvSize; this.tlvList.put(tlv.getType(), tlv); } return this; }
HexEncode.bytesToHexString(packetBytes));
"ARP Probing ({}) for {}({})", new Object[] { arp_cntdown, host.getNetworkAddress().getHostAddress(), HexEncode.bytesToHexString(host.getDataLayerAddressBytes()) });
logger.trace("{}: {}: {} (offset {} bitsize {})", new Object[] { this.getClass().getSimpleName(), hdrField, HexEncode.bytesToHexString(hdrFieldBytes), startOffset, numBits });
ofPacket.getPacketData().length, GlobalConstants.DEFAULT.toString(), HexEncode.bytesToHexString(dataPacket .getPacketData()) }); ofPacket.getPacketData().length, container, HexEncode.bytesToHexString(dataPacket .getPacketData()) });
/** * Send a unicast ARP Request to the known host on specific (switch/port, * vlan) as defined in the host. The sender IP is the networkAddress of the * subnet The sender MAC is the controller's MAC */ protected void sendUcastARPRequest(HostNodeConnector host, Subnet subnet) { log.trace("sendUcastARPRequest host:{} subnet:{}", host, subnet); NodeConnector outPort = host.getnodeConnector(); if (outPort == null) { log.error("Failed sending UcastARP because cannot extract output port from Host: {}", host); return; } byte[] senderIP = subnet.getNetworkAddress().getAddress(); byte[] targetIP = host.getNetworkAddress().getAddress(); byte[] targetMAC = host.getDataLayerAddressBytes(); ARP arp = createARP(ARP.REQUEST, getControllerMAC(), senderIP, targetMAC, targetIP); if(log.isTraceEnabled()) { log.trace("Sending Unicast Arp Request with srcMac {} - srcIp {} - dstMac {} - dstIp {} - outport {}", HexEncode.bytesToHexString(getControllerMAC()), subnet.getNetworkAddress(), HexEncode.bytesToHexString(targetMAC), host.getNetworkAddress(), outPort); } Ethernet ethernet = createEthernet(getControllerMAC(), targetMAC, arp, host.getVlan()); RawPacket destPkt = this.dataPacketService.encodeDataPacket(ethernet); destPkt.setOutgoingNodeConnector(outPort); this.dataPacketService.transmitDataPacket(destPkt); }
@Override public byte[] serialize() throws PacketException { int startOffset = 0; byte[] serializedBytes = new byte[getLLDPPacketLength()]; for (Map.Entry<Byte, LLDPTLV> entry : tlvList.entrySet()) { LLDPTLV tlv = entry.getValue(); int numBits = tlv.getTLVSize(); try { BitBufferHelper.setBytes(serializedBytes, tlv.serialize(), startOffset, numBits); } catch (BufferException e) { throw new PacketException(e.getMessage()); } startOffset += numBits; } // Now add the empty LLDPTLV at the end try { BitBufferHelper.setBytes(serializedBytes, LLDP.emptyTLV.serialize(), startOffset, LLDP.emptyTLV.getTLVSize()); } catch (BufferException e) { throw new PacketException(e.getMessage()); } if (logger.isTraceEnabled()) { logger.trace("LLDP: serialized: {}", HexEncode.bytesToHexString(serializedBytes)); } return serializedBytes; }
log.trace("Sending Broadcast Arp Request with srcMac {} - srcIp {} - dstMac {} - dstIp {} - outport {}", HexEncode.bytesToHexString(getControllerMAC()), subnet.getNetworkAddress(), HexEncode.bytesToHexString(targetHardwareAddress), targetIP, p);