/** * Generates a DHCP request OFPacketIn. * @param hostMac The host MAC address of for the request. * @return An OFPacketIn that contains a DHCP request packet. */ public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw, MacAddress hostMac) { byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize(); OFFactory factory = sw.getOFFactory(); OFPacketIn.Builder packetInBuilder = factory.buildPacketIn(); if (factory.getVersion() == OFVersion.OF_10) { packetInBuilder .setInPort(OFPort.of(1)) .setData(serializedPacket) .setReason(OFPacketInReason.NO_MATCH); } else { packetInBuilder .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build()) .setData(serializedPacket) .setReason(OFPacketInReason.NO_MATCH); } return packetInBuilder.build(); }
private OFPacketIn createPacketIn(String srcMAC, String dstMAC, String srcIp, String dstIp, short vlan) { IPacket testPacket = new Ethernet() .setDestinationMACAddress(dstMAC) .setSourceMACAddress(srcMAC) .setVlanID(vlan) .setEtherType(EthType.IPv4) .setPayload( new IPv4() .setTtl((byte) 128) .setSourceAddress(srcIp) .setDestinationAddress(dstIp) .setPayload(new UDP() .setSourcePort((short) 5000) .setDestinationPort((short) 5001) .setPayload(new Data(new byte[] {0x01})))); byte[] testPacketSerialized = testPacket.serialize(); OFPacketIn pi; // build out input packet pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setData(testPacketSerialized) .setReason(OFPacketInReason.NO_MATCH) .build(); return pi; }
/** * Test dispatch of messages while in MASTER role */ @Test public void testMessageDispatchMaster() throws Exception { testInitialMoveToMasterWithRole(); // Send packet in. expect dispatch OFPacketIn pi = factory.buildPacketIn() .setReason(OFPacketInReason.NO_MATCH) .build(); reset(switchManager); switchManager.handleMessage(sw, pi, null); expectLastCall().once(); replay(switchManager); switchHandler.processOFMessage(pi); // TODO: many more to go }
private OFPacketIn createPacketIn(String srcMAC, String dstMAC, String srcIp, String dstIp, short vlan) { IPacket testPacket = new Ethernet() .setDestinationMACAddress(dstMAC) .setSourceMACAddress(srcMAC) .setVlanID(vlan) .setEtherType(Ethernet.TYPE_IPv4) .setPayload( new IPv4() .setTtl((byte) 128) .setSourceAddress(srcIp) .setDestinationAddress(dstIp) .setPayload(new UDP() .setSourcePort((short) 5000) .setDestinationPort((short) 5001) .setPayload(new Data(new byte[] {0x01})))); byte[] testPacketSerialized = testPacket.serialize(); OFPacketIn pi; // build out input packet pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setData(testPacketSerialized) .setReason(OFPacketInReason.NO_MATCH) .build(); return pi; }
OpenFlowMessage getMsgTestPacketIn(long dpid, int xid) { Ethernet ethernet = new Ethernet().setEtherType(Ethernet.TYPE_IPV4).setSourceMACAddress(MacAddress.valueOf(42)).setDestinationMACAddress(MacAddress.valueOf(0xdd43)); IPv4 iPv4 = new IPv4().setProtocol(IPv4.PROTOCOL_TCP); TCP tcp = new TCP().setSourcePort((short) 1000).setDestinationPort((short) 2000); tcp.setPayload(new Data(new byte[]{0x1a, 0x1b, 0x1c, 0x1d, 0x1e})); iPv4.setPayload(tcp); ethernet.setPayload(iPv4); OFPacketIn newPacketIn = OFFactories.getFactory(OFVersion.OF_10).buildPacketIn().setData(ethernet.serialize()).setReason(OFPacketInReason.NO_MATCH).build(); OpenFlowMessage newMessage = new OpenFlowMessage(); newMessage.setOfMessage(newPacketIn); MessageHeader header = new MessageHeader(); header.setTransactionId(xid); newMessage.getHeader().setDatapathId(dpid); return newMessage; }
@Test public void handlePacket() { OFPacketIn pkt = sw.factory().buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setInPort(OFPort.NO_MASK) .setReason(OFPacketInReason.INVALID_TTL) .build(); controller.processPacket(null, pkt); assertNotNull("message unprocessed", registry.ctx); }
/** * Updates testUDPPacketIn and testUDPPacketSrld from testUDPPacket * To be called after testUDPPacket has been mangled. */ private void updateUDPPacketIn() { this.testUDPPacketSrld = this.testUDPPacket.serialize(); // Build the PacketIn this.testUDPPacketIn = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setMatch(OFFactories.getFactory(OFVersion.OF_13).buildMatch().setExact(MatchField.IN_PORT, OFPort.of(3)).build()) .setData(this.testUDPPacketSrld) .setReason(OFPacketInReason.NO_MATCH) .build(); }
@Before public void setUp() throws Exception { super.setUp(); mockFloodlightProvider = getMockFloodlightProvider(); hub = new Hub(); mockFloodlightProvider.addOFMessageListener(OFType.PACKET_IN, hub); hub.setFloodlightProvider(mockFloodlightProvider); // Build our test packet this.testPacket = new Ethernet() .setDestinationMACAddress("00:11:22:33:44:55") .setSourceMACAddress("00:44:33:22:11:00") .setEtherType(EthType.IPv4) .setPayload( new IPv4() .setTtl((byte) 128) .setSourceAddress("192.168.1.1") .setDestinationAddress("192.168.1.2") .setPayload(new UDP() .setSourcePort((short) 5000) .setDestinationPort((short) 5001) .setPayload(new Data(new byte[] {0x01})))); this.testPacketSerialized = testPacket.serialize(); // Build the PacketIn this.packetIn = (OFPacketIn) OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setMatch(OFFactories.getFactory(OFVersion.OF_13).buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(1)) .build()) .setData(this.testPacketSerialized) .setReason(OFPacketInReason.NO_MATCH) .setTotalLen((short) this.testPacketSerialized.length).build(); }
protected void setPacketIn(IPacket packet) { byte[] serializedPacket = packet.serialize(); // Build the PacketIn this.packetIn = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setMatch(OFFactories.getFactory(OFVersion.OF_13).buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build()) .setData(serializedPacket) .setReason(OFPacketInReason.NO_MATCH) .build(); // Add the packet to the context store IFloodlightProviderService.bcStore. put(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD, (Ethernet)packet); }