Search in sources :

Example 31 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class GroupVerifyCommand method validateGroupConfig.

private void validateGroupConfig(OFGroupDescStatsEntry group) {
    DatapathId datapathId = getSw().getId();
    OFFactory ofFactory = getSw().getOFFactory();
    List<OFBucket> expected = buildGroupOfBuckets(ofFactory);
    List<OFBucket> actual = group.getBuckets();
    if (!expected.equals(actual)) {
        throw maskCallbackException(new SwitchIncorrectMirrorGroupException(datapathId, mirrorConfig, fromStatsEntry(group)));
    }
}
Also used : OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) SwitchIncorrectMirrorGroupException(org.openkilda.floodlight.error.SwitchIncorrectMirrorGroupException) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) DatapathId(org.projectfloodlight.openflow.types.DatapathId)

Example 32 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class OfBatchHolder method addDeleteFlow.

@Override
public void addDeleteFlow(FlowSpeakerData data, SwitchId switchId) {
    DatapathId dpId = DatapathId.of(switchId.toLong());
    OFFactory factory = iofSwitchService.getSwitch(dpId).getOFFactory();
    OFMessage message = OfFlowConverter.INSTANCE.convertDeleteFlowCommand(data, factory);
    xidMapping.put(message.getXid(), data.getUuid());
    commandMap.put(data.getUuid(), BatchData.builder().flow(true).message(message).build());
    flowsMap.put(data.getCookie(), data);
    executionGraph.add(data.getUuid(), data.getDependsOn());
}
Also used : OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) DatapathId(org.projectfloodlight.openflow.types.DatapathId)

Example 33 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class OfBatchHolder method addInstallMeter.

@Override
public void addInstallMeter(MeterSpeakerData data, SwitchId switchId) {
    DatapathId dpId = DatapathId.of(switchId.toLong());
    OFFactory factory = iofSwitchService.getSwitch(dpId).getOFFactory();
    OFMessage message = OfMeterConverter.INSTANCE.convertInstallMeterCommand(data, factory);
    xidMapping.put(message.getXid(), data.getUuid());
    commandMap.put(data.getUuid(), BatchData.builder().meter(true).message(message).build());
    metersMap.put(data.getMeterId(), data);
    executionGraph.add(data.getUuid(), data.getDependsOn());
}
Also used : OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) DatapathId(org.projectfloodlight.openflow.types.DatapathId)

Example 34 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class PathVerificationPacketSignTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    final OFPacketOut packetOut = pvs.generateDiscoveryPacket(sw1, OFPort.of(1), true, null);
    ofPacketIn = EasyMock.createMock(OFPacketIn.class);
    context = new FloodlightContext();
    expect(ofPacketIn.getType()).andReturn(OFType.PACKET_IN).anyTimes();
    expect(ofPacketIn.getXid()).andReturn(0L).anyTimes();
    expect(ofPacketIn.getVersion()).andReturn(packetOut.getVersion()).anyTimes();
    expect(ofPacketIn.getCookie()).andReturn(PathVerificationService.OF_CATCH_RULE_COOKIE);
    Match match = EasyMock.createMock(Match.class);
    expect(match.get(MatchField.IN_PORT)).andReturn(OFPort.of(1)).anyTimes();
    replay(match);
    expect(ofPacketIn.getMatch()).andReturn(match).anyTimes();
    replay(ofPacketIn);
    IPacket expected = new Ethernet().deserialize(packetOut.getData(), 0, packetOut.getData().length);
    context.getStorage().put(IFloodlightProviderService.CONTEXT_PI_PAYLOAD, expected);
    HashMap<DatapathId, IOFSwitch> switches = new HashMap<>();
    switches.put(sw1.getId(), sw1);
    switches.put(sw2.getId(), sw2);
    mockSwitchManager.setSwitches(switches);
}
Also used : IPacket(net.floodlightcontroller.packet.IPacket) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) HashMap(java.util.HashMap) Ethernet(net.floodlightcontroller.packet.Ethernet) OFPacketIn(org.projectfloodlight.openflow.protocol.OFPacketIn) DatapathId(org.projectfloodlight.openflow.types.DatapathId) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Match(org.projectfloodlight.openflow.protocol.match.Match) Before(org.junit.Before)

Example 35 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId 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);
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFConnection(net.floodlightcontroller.core.internal.OFConnection) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) CorrelationContextClosable(org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) IpSocketAddress(org.openkilda.model.IpSocketAddress) IAnswer(org.easymock.IAnswer) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) InfoMessage(org.openkilda.messaging.info.InfoMessage) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFSwitch(net.floodlightcontroller.core.internal.OFSwitch) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) SwitchDescription(net.floodlightcontroller.core.SwitchDescription) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) Test(org.junit.Test)

Aggregations

DatapathId (org.projectfloodlight.openflow.types.DatapathId)55 InfoMessage (org.openkilda.messaging.info.InfoMessage)19 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)17 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)16 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)16 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)16 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)15 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)14 SwitchId (org.openkilda.model.SwitchId)14 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)13 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)12 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)10 ArrayList (java.util.ArrayList)9 InetSocketAddress (java.net.InetSocketAddress)8 HashSet (java.util.HashSet)8 Map (java.util.Map)8 InvalidMeterIdException (org.openkilda.floodlight.error.InvalidMeterIdException)8 OfInstallException (org.openkilda.floodlight.error.OfInstallException)8 Objects (java.util.Objects)7 Collectors (java.util.stream.Collectors)7