use of org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13 in project open-kilda by telstra.
the class PingResponseCommandTest method skipByCookie.
@Test
public void skipByCookie() throws Exception {
replayAll();
OFFactory ofFactory = new OFFactoryVer13();
OFMessage message = ofFactory.buildPacketIn().setReason(OFPacketInReason.ACTION).setXid(1).setCookie(U64.of(PingService.OF_CATCH_RULE_COOKIE.hashCode() + 1)).build();
FloodlightContext floodlightContext = new FloodlightContext();
OfInput input = new OfInput(iofSwitch, message, floodlightContext);
PingResponseCommand command = makeCommand(input);
expectSkip(command);
}
use of org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13 in project open-kilda by telstra.
the class OfMatchConverterTest method testConvertMatchExact.
@Test
public void testConvertMatchExact() {
OFFactoryVer13 factory = new OFFactoryVer13();
Set<FieldMatch> matchSet = new HashSet<>();
matchSet.add(FieldMatch.builder().field(Field.ETH_TYPE).value(0x0800L).build());
matchSet.add(FieldMatch.builder().field(Field.ETH_SRC).value(1).build());
matchSet.add(FieldMatch.builder().field(Field.ETH_DST).value(2).build());
matchSet.add(FieldMatch.builder().field(Field.IP_PROTO).value(17).build());
matchSet.add(FieldMatch.builder().field(Field.UDP_SRC).value(11).build());
matchSet.add(FieldMatch.builder().field(Field.UDP_DST).value(22).build());
matchSet.add(FieldMatch.builder().field(Field.IN_PORT).value(333).build());
matchSet.add(FieldMatch.builder().field(Field.METADATA).value(44).build());
matchSet.add(FieldMatch.builder().field(Field.VLAN_VID).value(3000).build());
matchSet.add(FieldMatch.builder().field(Field.NOVIFLOW_TUNNEL_ID).value(321).build());
matchSet.add(FieldMatch.builder().field(Field.OVS_VXLAN_VNI).value(123).build());
Match match = OfMatchConverter.INSTANCE.convertMatch(matchSet, factory);
EthType ethType = match.get(MatchField.ETH_TYPE);
assertEquals(0x800, ethType.getValue());
MacAddress ethSrc = match.get(MatchField.ETH_SRC);
assertEquals(MacAddress.of(1), ethSrc);
MacAddress ethDst = match.get(MatchField.ETH_DST);
assertEquals(MacAddress.of(2), ethDst);
IpProtocol ipProto = match.get(MatchField.IP_PROTO);
assertEquals(IpProtocol.of((short) 17), ipProto);
TransportPort udpSrc = match.get(MatchField.UDP_SRC);
assertEquals(TransportPort.of(11), udpSrc);
TransportPort udpDst = match.get(MatchField.UDP_DST);
assertEquals(TransportPort.of(22), udpDst);
OFPort inPort = match.get(MatchField.IN_PORT);
assertEquals(OFPort.of(333), inPort);
OFMetadata metadata = match.get(MatchField.METADATA);
assertEquals(OFMetadata.of(U64.of(44)), metadata);
OFVlanVidMatch vlanVidMasked = match.get(MatchField.VLAN_VID);
assertEquals(OFVlanVidMatch.ofVlan(3000), vlanVidMasked);
U64 tunnelId = match.get(MatchField.TUNNEL_ID);
assertEquals(U64.of(321), tunnelId);
U32 vxlanVni = match.get(MatchField.KILDA_VXLAN_VNI);
assertEquals(U32.of(123), vxlanVni);
}
use of org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13 in project open-kilda by telstra.
the class OfMatchConverterTest method testConvertMatchMasked.
@Test
public void testConvertMatchMasked() {
OFFactoryVer13 factory = new OFFactoryVer13();
Set<FieldMatch> matchSet = new HashSet<>();
matchSet.add(FieldMatch.builder().field(Field.ETH_TYPE).value(0x0800L).mask(0x0800L).build());
matchSet.add(FieldMatch.builder().field(Field.ETH_SRC).value(1).mask(1L).build());
matchSet.add(FieldMatch.builder().field(Field.ETH_DST).value(2).mask(2L).build());
matchSet.add(FieldMatch.builder().field(Field.IP_PROTO).value(17).mask(17L).build());
matchSet.add(FieldMatch.builder().field(Field.UDP_SRC).value(11).mask(11L).build());
matchSet.add(FieldMatch.builder().field(Field.UDP_DST).value(22).mask(22L).build());
matchSet.add(FieldMatch.builder().field(Field.IN_PORT).value(333).mask(333L).build());
matchSet.add(FieldMatch.builder().field(Field.METADATA).value(44).mask(44L).build());
matchSet.add(FieldMatch.builder().field(Field.VLAN_VID).value(3000).mask(3000L).build());
matchSet.add(FieldMatch.builder().field(Field.NOVIFLOW_TUNNEL_ID).value(321).mask(321L).build());
Match match = OfMatchConverter.INSTANCE.convertMatch(matchSet, factory);
Masked<EthType> ethTypeMasked = match.getMasked(MatchField.ETH_TYPE);
assertEquals(0x800, ethTypeMasked.getValue().getValue());
assertEquals(0x800, ethTypeMasked.getMask().getValue());
Masked<MacAddress> ethSrcMasked = match.getMasked(MatchField.ETH_SRC);
assertEquals(MacAddress.of(1), ethSrcMasked.getValue());
assertEquals(MacAddress.of(1), ethSrcMasked.getMask());
Masked<MacAddress> ethDstMasked = match.getMasked(MatchField.ETH_DST);
assertEquals(MacAddress.of(2), ethDstMasked.getValue());
assertEquals(MacAddress.of(2), ethDstMasked.getMask());
Masked<IpProtocol> ipProtoMasked = match.getMasked(MatchField.IP_PROTO);
assertEquals(IpProtocol.of((short) 17), ipProtoMasked.getValue());
assertEquals(IpProtocol.of((short) 17), ipProtoMasked.getMask());
Masked<TransportPort> udpSrcMasked = match.getMasked(MatchField.UDP_SRC);
assertEquals(TransportPort.of(11), udpSrcMasked.getValue());
assertEquals(TransportPort.of(11), udpSrcMasked.getMask());
Masked<TransportPort> udpDstMasked = match.getMasked(MatchField.UDP_DST);
assertEquals(TransportPort.of(22), udpDstMasked.getValue());
assertEquals(TransportPort.of(22), udpDstMasked.getMask());
Masked<OFPort> inPortMasked = match.getMasked(MatchField.IN_PORT);
assertEquals(OFPort.of(333), inPortMasked.getValue());
assertEquals(OFPort.of(333), inPortMasked.getMask());
Masked<OFMetadata> metadataMasked = match.getMasked(MatchField.METADATA);
assertEquals(OFMetadata.of(U64.of(44)), metadataMasked.getValue());
assertEquals(OFMetadata.of(U64.of(44)), metadataMasked.getMask());
Masked<OFVlanVidMatch> vlanVidMasked = match.getMasked(MatchField.VLAN_VID);
assertEquals(OFVlanVidMatch.ofVlan(3000), vlanVidMasked.getValue());
assertEquals(OFVlanVidMatch.ofVlan(3000), vlanVidMasked.getMask());
Masked<U64> tunnelIdMasked = match.getMasked(MatchField.TUNNEL_ID);
assertEquals(U64.of(321), tunnelIdMasked.getValue());
assertEquals(U64.of(321), tunnelIdMasked.getMask());
}
use of org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13 in project open-kilda by telstra.
the class OfFlowPresenceVerifierTest method testInaccurateSetFieldVlanVidAction.
public OfFlowPresenceVerifier testInaccurateSetFieldVlanVidAction(Set<SwitchFeature> switchFeatures) {
OFFactory of = new OFFactoryVer13();
final int priority = 1000;
final U64 cookie = U64.of(2000);
final Match match = of.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build();
final short vlanId = 512;
OFFlowStatsEntry switchResponseEntry = of.buildFlowStatsEntry().setTableId(TableId.of(0)).setPriority(priority).setCookie(cookie).setMatch(match).setInstructions(Collections.singletonList(of.instructions().applyActions(Collections.singletonList(of.actions().setField(of.oxms().vlanVid(OFVlanVidMatch.ofRawVid(vlanId))))))).build();
CompletableFuture<List<OFFlowStatsEntry>> switchFlowStatsResponse = CompletableFuture.completedFuture(Collections.singletonList(switchResponseEntry));
EasyMock.expect(dumpProducer.getTableRequests()).andReturn(Collections.singletonList(switchFlowStatsResponse));
replayAll();
OFFlowAdd expected = of.buildFlowAdd().setPriority(priority).setCookie(cookie).setMatch(match).setInstructions(Collections.singletonList(of.instructions().applyActions(Collections.singletonList(OfAdapter.INSTANCE.setVlanIdAction(of, 512))))).build();
OfFlowPresenceVerifier presenceVerifier = new OfFlowPresenceVerifier(dumpProducer, Collections.singletonList(expected), switchFeatures);
Assert.assertTrue(presenceVerifier.getFinish().isDone());
return presenceVerifier;
}
use of org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13 in project open-kilda by telstra.
the class SwitchTrackingServiceTest method networkDumpTest.
@Test
public void networkDumpTest() throws Exception {
// Cook mock data for ISwitchManager::getAllSwitchMap
// Two switches with two ports on each
// switches for ISwitchManager::getAllSwitchMap
OFSwitch iofSwitch1 = mock(OFSwitch.class);
OFSwitch iofSwitch2 = mock(OFSwitch.class);
final DatapathId swAid = DatapathId.of(1);
final DatapathId swBid = DatapathId.of(2);
Map<DatapathId, IOFSwitch> switches = ImmutableMap.of(swAid, iofSwitch1, swBid, iofSwitch2);
Map<DatapathId, InetSocketAddress> switchAddresses = ImmutableMap.of(swAid, new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768), swBid, new InetSocketAddress(Inet4Address.getByName("127.0.1.2"), 32768));
SwitchDescription ofSwitchDescription = new SwitchDescription(switchDescription.getManufacturer(), switchDescription.getHardware(), switchDescription.getSoftware(), switchDescription.getSerialNumber(), switchDescription.getDatapath());
OFFactoryVer13 ofFactory = new OFFactoryVer13();
InetSocketAddress switchSocketAddress = new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768);
for (DatapathId swId : switches.keySet()) {
IOFSwitch sw = switches.get(swId);
expect(sw.getOFFactory()).andStubReturn(ofFactory);
expect(sw.isActive()).andReturn(true).anyTimes();
expect(sw.getId()).andReturn(swId).anyTimes();
expect(sw.getSwitchDescription()).andReturn(ofSwitchDescription);
expect(sw.getInetAddress()).andReturn(switchAddresses.get(swId));
expect(sw.getControllerRole()).andStubReturn(OFControllerRole.ROLE_EQUAL);
OFConnection connect = createMock(OFConnection.class);
expect(connect.getRemoteInetAddress()).andReturn(switchSocketAddress);
expect(sw.getConnectionByCategory(eq(LogicalOFMessageCategory.MAIN))).andReturn(connect);
}
expect(switchManager.getAllSwitchMap(true)).andReturn(switches);
expect(switchManager.getPhysicalPorts(eq(iofSwitch1))).andReturn(ImmutableList.of(makePhysicalPortMock(1, true), makePhysicalPortMock(2, true)));
expect(switchManager.getPhysicalPorts(eq(iofSwitch2))).andReturn(ImmutableList.of(makePhysicalPortMock(3, true), makePhysicalPortMock(4, true), makePhysicalPortMock(5, false)));
expect(featureDetector.detectSwitch(iofSwitch1)).andReturn(ImmutableSet.of(SwitchFeature.METERS));
expect(featureDetector.detectSwitch(iofSwitch2)).andReturn(ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD));
ArrayList<Message> producedMessages = new ArrayList<>();
// setup hook for verify that we create new message for producer
producerService.sendMessageAndTrack(eq(KAFKA_ISL_DISCOVERY_TOPIC), anyObject(), anyObject(InfoMessage.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() {
Message sentMessage = (Message) getCurrentArguments()[2];
sentMessage.setTimestamp(0);
producedMessages.add(sentMessage);
return null;
}
}).anyTimes();
replayAll();
String correlationId = "unit-test-correlation-id";
String dumpId = "dummy-dump-id";
try (CorrelationContextClosable dummy = CorrelationContext.create(correlationId)) {
service.dumpAllSwitches(dumpId);
}
verify(producerService);
ArrayList<Message> expectedMessages = new ArrayList<>();
expectedMessages.add(new InfoMessage(new NetworkDumpSwitchData(new SpeakerSwitchView(new SwitchId(swAid.getLong()), new IpSocketAddress("127.0.1.1", 32768), new IpSocketAddress("127.0.1.254", 6653), "127.0.1.1", "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS), ImmutableList.of(new SpeakerSwitchPortView(1, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(2, SpeakerSwitchPortView.State.UP))), dumpId, true), 0, correlationId));
expectedMessages.add(new InfoMessage(new NetworkDumpSwitchData(new SpeakerSwitchView(new SwitchId(swBid.getLong()), new IpSocketAddress("127.0.1.2", 32768), new IpSocketAddress("127.0.1.254", 6653), "127.0.1.2", "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD), ImmutableList.of(new SpeakerSwitchPortView(3, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(4, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(5, SpeakerSwitchPortView.State.DOWN))), dumpId, true), 0, correlationId));
assertEquals(expectedMessages, producedMessages);
}
Aggregations