use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project netvirt by opendaylight.
the class Ipv6PktHandlerTest method testonPacketReceivedRouterSolicitationWithSingleSubnet.
@Test
public void testonPacketReceivedRouterSolicitationWithSingleSubnet() throws Exception {
VirtualPort intf = Mockito.mock(VirtualPort.class);
when(intf.getMacAddress()).thenReturn("fa:16:3e:4e:18:0c");
when(ifMgrInstance.getInterfaceNameFromTag(anyLong())).thenReturn("ddec9dba-d831-4ad7-84b9-00d7f65f052f");
when(ifMgrInstance.obtainV6Interface(any())).thenReturn(intf);
when(ifMgrInstance.getRouterV6InterfaceForNetwork(any())).thenReturn(intf);
IpAddress gwIpAddress = Mockito.mock(IpAddress.class);
when(gwIpAddress.getIpv4Address()).thenReturn(null);
when(gwIpAddress.getIpv6Address()).thenReturn(new Ipv6Address("2001:db8::1"));
VirtualSubnet v6Subnet = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_SLAAC).ipv6RAMode(Ipv6Constants.IPV6_SLAAC).build();
VirtualRouter virtualRouter = VirtualRouter.builder().build();
v6Subnet.setRouter(virtualRouter);
List<VirtualSubnet> subnetList = new ArrayList<>();
subnetList.add(v6Subnet);
when(intf.getSubnets()).thenReturn(subnetList);
InstanceIdentifier<Node> ncId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1"))).build();
NodeConnectorRef ncRef = new NodeConnectorRef(ncId);
BigInteger mdata = new BigInteger(String.valueOf(0x1000000));
Metadata metadata = new MetadataBuilder().setMetadata(mdata).build();
MatchBuilder matchbuilder = new MatchBuilder().setMetadata(metadata);
pktHandler.onPacketReceived(new PacketReceivedBuilder().setPayload(ipv6TestUtils.buildPacket(// Destination MAC
"33 33 00 00 00 02", // Source MAC
"FA 16 3E 69 2C F3", // IPv6
"86 DD", // Version 6, traffic class E0, no flowlabel
"60 00 00 00", // Payload length
"00 10", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 69 2C F3", // Destination IP
"FF 02 00 00 00 00 00 00 00 00 00 00 00 00 00 02", // ICMPv6 router solicitation
"85", // Code
"00", // Checksum (valid)
"B4 47", // ICMPv6 message body
"00 00 00 00", // ICMPv6 Option: Source Link Layer Address
"01", // Length
"01", // Link Layer Address
"FA 16 3E 69 2C F3")).setIngress(ncRef).setMatch(matchbuilder.build()).build());
// wait on this thread until the async job is completed in the packet handler.
waitForPacketProcessing();
verify(pktProcessService, times(1)).transmitPacket(any(TransmitPacketInput.class));
byte[] expectedPayload = ipv6TestUtils.buildPacket(// Destination MAC
"FA 16 3E 69 2C F3", // Source MAC
"FA 16 3E 4E 18 0C", // IPv6
"86 DD", // Version 6, traffic class E0, no flowlabel
"60 00 00 00", // Payload length
"00 38", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 4E 18 0C", // Destination IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 69 2C F3", // ICMPv6 router advertisement.
"86", // Code
"00", // Checksum (valid)
"1B B0", // Current Hop Limit
"40", // ICMPv6 RA Flags
"00", // Router Lifetime
"11 94", // Reachable time
"00 01 D4 C0", // Retransmission time.
"00 00 00 00", // Type: Source Link-Layer Option
"01", // Option length
"01", // Source Link layer address
"FA 16 3E 4E 18 0C", // Type: Prefix Information
"03", // Option length
"04", // Prefix length
"40", // Prefix flags
"C0", // Valid lifetime
"00 27 8D 00", // Preferred lifetime
"00 09 3A 80", // Reserved
"00 00 00 00", // Prefix
"20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 00");
verify(pktProcessService).transmitPacket(new TransmitPacketInputBuilder().setPayload(expectedPayload).setNode(new NodeRef(ncId)).setEgress(ncRef).build());
}
use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project netvirt by opendaylight.
the class Ipv6PktHandlerTest method testonPacketReceivedNeighborSolicitationWithValidPayload.
@Test
public void testonPacketReceivedNeighborSolicitationWithValidPayload() throws Exception {
VirtualPort intf = Mockito.mock(VirtualPort.class);
when(intf.getNetworkID()).thenReturn(new Uuid("eeec9dba-d831-4ad7-84b9-00d7f65f0555"));
when(ifMgrInstance.getInterfaceNameFromTag(anyLong())).thenReturn("ddec9dba-d831-4ad7-84b9-00d7f65f052f");
when(ifMgrInstance.obtainV6Interface(any())).thenReturn(intf);
VirtualPort routerIntf = Mockito.mock(VirtualPort.class);
when(ifMgrInstance.getRouterV6InterfaceForNetwork(any())).thenReturn(routerIntf);
List<Ipv6Address> ipv6AddrList = new ArrayList<>();
when(routerIntf.getMacAddress()).thenReturn("08:00:27:FE:8F:95");
Ipv6Address llAddr = Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(new MacAddress("08:00:27:FE:8F:95"));
ipv6AddrList.add(llAddr);
when(routerIntf.getIpv6Addresses()).thenReturn(ipv6AddrList);
InstanceIdentifier<Node> ncId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1"))).build();
NodeConnectorRef ncRef = new NodeConnectorRef(ncId);
BigInteger mdata = new BigInteger(String.valueOf(0x1000000));
Metadata metadata = new MetadataBuilder().setMetadata(mdata).build();
MatchBuilder matchbuilder = new MatchBuilder().setMetadata(metadata);
pktHandler.onPacketReceived(new PacketReceivedBuilder().setPayload(ipv6TestUtils.buildPacket(// Destination MAC
"33 33 FF FE 8F 95", // Source MAC
"08 00 27 D4 10 BB", // IPv6
"86 DD", // Version 6, traffic class 0, no flowlabel
"60 00 00 00", // Payload length
"00 20", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 0A 00 27 FF FE D4 10 BB", // Destination IP
"FF 02 00 00 00 00 00 00 00 00 00 01 FF FE 8F 95", // ICMPv6 neighbor solicitation
"87", // Code
"00", // Checksum (valid)
"A9 57", // ICMPv6 message body
"00 00 00 00", // Target
"FE 80 00 00 00 00 00 00 0A 00 27 FF FE FE 8F 95", // ICMPv6 Option: Source Link Layer Address
"01", // Length
"01", // Link Layer Address
"08 00 27 D4 10 BB")).setIngress(ncRef).setMatch(matchbuilder.build()).build());
// wait on this thread until the async job is completed in the packet handler.
waitForPacketProcessing();
verify(pktProcessService, times(1)).transmitPacket(any(TransmitPacketInput.class));
byte[] expectedPayload = ipv6TestUtils.buildPacket(// Destination MAC
"08 00 27 D4 10 BB", // Source MAC
"08 00 27 FE 8F 95", // Ethertype - IPv6
"86 DD", // Version 6, traffic class 0, no flowlabel
"60 00 00 00", // Payload length
"00 20", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 0A 00 27 FF FE FE 8F 95", // Destination IP
"FE 80 00 00 00 00 00 00 0A 00 27 FF FE D4 10 BB", // ICMPv6 neighbor advertisement.
"88", // Code
"00", // Checksum (valid)
"17 D6", // Flags
"E0 00 00 00", // Target Address
"FE 80 00 00 00 00 00 00 0A 00 27 FF FE FE 8F 95", // Type: Target Link-Layer Option
"02", // Option length
"01", // Target Link layer address
"08 00 27 FE 8F 95");
verify(pktProcessService).transmitPacket(new TransmitPacketInputBuilder().setPayload(expectedPayload).setNode(new NodeRef(ncId)).setEgress(ncRef).build());
}
use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project openflowplugin by opendaylight.
the class LLDPSpeaker method nodeConnectorAdded.
@Override
public void nodeConnectorAdded(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId, final FlowCapableNodeConnector flowConnector) {
NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(nodeConnectorInstanceId).getId();
// port, so first we check if we actually need to perform any action
if (nodeConnectorMap.containsKey(nodeConnectorInstanceId)) {
LOG.debug("Port {} already in LLDPSpeaker.nodeConnectorMap, no need for additional processing", nodeConnectorId.getValue());
return;
}
// Prepare to build LLDP payload
InstanceIdentifier<Node> nodeInstanceId = nodeConnectorInstanceId.firstIdentifierOf(Node.class);
NodeId nodeId = InstanceIdentifier.keyOf(nodeInstanceId).getId();
MacAddress srcMacAddress = flowConnector.getHardwareAddress();
Long outputPortNo = flowConnector.getPortNumber().getUint32();
// No need to send LLDP frames on local ports
if (outputPortNo == null) {
LOG.debug("Port {} is local, not sending LLDP frames through it", nodeConnectorId.getValue());
return;
}
// Generate packet with destination switch and port
TransmitPacketInput packet;
try {
packet = new TransmitPacketInputBuilder().setEgress(new NodeConnectorRef(nodeConnectorInstanceId)).setNode(new NodeRef(nodeInstanceId)).setPayload(LLDPUtil.buildLldpFrame(nodeId, nodeConnectorId, srcMacAddress, outputPortNo, addressDestionation)).build();
} catch (NoSuchAlgorithmException | PacketException e) {
LOG.error("Error building LLDP frame", e);
return;
}
// Save packet to node connector id -> packet map to transmit it periodically on the configured interval.
nodeConnectorMap.put(nodeConnectorInstanceId, packet);
LOG.debug("Port {} added to LLDPSpeaker.nodeConnectorMap", nodeConnectorId.getValue());
// Transmit packet for first time immediately
final Future<RpcResult<Void>> resultFuture = packetProcessingService.transmitPacket(packet);
JdkFutures.addErrorLogging(resultFuture, LOG, "transmitPacket");
}
use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project openflowplugin by opendaylight.
the class PacketInMessageDeserializerTest method deserialize.
@Test
public void deserialize() throws Exception {
buffer.writeByte(TYPE);
buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
buffer.writeInt(XID);
// Buffer id - irrelevant
buffer.writeInt(EncodeConstants.EMPTY_VALUE);
// Total len - irrelevant
buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
buffer.writeByte(REASON);
buffer.writeByte(TABLE_ID);
buffer.writeLong(FLOW_COOKIE);
// Match header
int matchStartIndex = buffer.writerIndex();
buffer.writeShort(OXM_MATCH_TYPE_CODE);
int matchLengthIndex = buffer.writerIndex();
buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
// MplsLabel match
buffer.writeShort(OxmMatchConstants.OPENFLOW_BASIC_CLASS);
buffer.writeByte(OxmMatchConstants.MPLS_LABEL << 1);
buffer.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES);
buffer.writeInt(MPLS_LABEL);
// Match footer
int matchLength = buffer.writerIndex() - matchStartIndex;
buffer.setShort(matchLengthIndex, matchLength);
int paddingRemainder = matchLength % EncodeConstants.PADDING;
if (paddingRemainder != 0) {
buffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
}
buffer.writeZero(PADDING_IN_PACKET_IN_HEADER);
buffer.writeBytes(PAYLOAD);
final PacketInMessage message = (PacketInMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
assertEquals(XID, message.getXid().intValue());
assertEquals(PacketInUtil.getMdSalPacketInReason(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason.forValue(REASON)), message.getPacketInReason());
assertEquals(TABLE_ID, message.getTableId().getValue().shortValue());
assertEquals(FLOW_COOKIE, message.getFlowCookie().getValue().longValue());
assertEquals(MPLS_LABEL, message.getMatch().getProtocolMatchFields().getMplsLabel().intValue());
assertArrayEquals(PAYLOAD, message.getPayload());
assertEquals(buffer.readableBytes(), 0);
}
use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project openflowplugin by opendaylight.
the class LearningSwitchHandlerSimpleImpl method sendPacketOut.
private void sendPacketOut(byte[] payload, NodeConnectorRef ingress, NodeConnectorRef egress) {
InstanceIdentifier<Node> egressNodePath = InstanceIdentifierUtils.getNodePath(egress.getValue());
TransmitPacketInput input = new TransmitPacketInputBuilder().setPayload(payload).setNode(new NodeRef(egressNodePath)).setEgress(egress).setIngress(ingress).build();
JdkFutures.addErrorLogging(packetProcessingService.transmitPacket(input), LOG, "transmitPacket");
}
Aggregations