Search in sources :

Example 11 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByInPortAndVlan.

@Test
public void shouldDeleteRuleByInPortAndVlan() throws Exception {
    // given
    final int testInPort = 11;
    final short testInVlan = 101;
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().inPort(testInPort).encapsulationId((int) testInVlan).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).egressSwitchId(SWITCH_ID).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(testInPort, actual.getMatch().get(MatchField.IN_PORT).getPortNumber());
    assertEquals(testInVlan, actual.getMatch().get(MatchField.VLAN_VID).getVlan());
    assertEquals("any", actual.getOutPort().toString());
    assertEquals(0, actual.getInstructions().size());
    assertEquals(0L, actual.getCookie().getValue());
    assertEquals(0L, actual.getCookieMask().getValue());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 12 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByInPortVlanAndMetadata.

@Test
public void shouldDeleteRuleByInPortVlanAndMetadata() throws Exception {
    // given
    final int testInPort = 11;
    final short testInVlan = 101;
    final long metadataValue = 17;
    final long metadataMask = 255;
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().inPort(testInPort).metadataValue(metadataValue).metadataMask(metadataMask).encapsulationId((int) testInVlan).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).egressSwitchId(SWITCH_ID).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(testInPort, actual.getMatch().get(MatchField.IN_PORT).getPortNumber());
    assertEquals(testInVlan, actual.getMatch().get(MatchField.VLAN_VID).getVlan());
    assertEquals(metadataValue, actual.getMatch().getMasked(MatchField.METADATA).getValue().getValue().getValue());
    assertEquals(metadataMask, actual.getMatch().getMasked(MatchField.METADATA).getMask().getValue().getValue());
    assertEquals("any", actual.getOutPort().toString());
    assertEquals(0, actual.getInstructions().size());
    assertEquals(0L, actual.getCookie().getValue());
    assertEquals(0L, actual.getCookieMask().getValue());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 13 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByOutPort.

@Test
public void shouldDeleteRuleByOutPort() throws Exception {
    // given
    final int testOutPort = 21;
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().outPort(testOutPort).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertNull(actual.getMatch().get(MatchField.IN_PORT));
    assertNull(actual.getMatch().get(MatchField.VLAN_VID));
    assertEquals(testOutPort, actual.getOutPort().getPortNumber());
    assertEquals(0L, actual.getCookie().getValue());
    assertEquals(0L, actual.getCookieMask().getValue());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 14 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByPriority.

@Test
public void shouldDeleteRuleByPriority() throws Exception {
    // given
    final int testPriority = 999;
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().priority(testPriority).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertNull(actual.getMatch().get(MatchField.IN_PORT));
    assertNull(actual.getMatch().get(MatchField.VLAN_VID));
    assertEquals("any", actual.getOutPort().toString());
    assertEquals(0, actual.getInstructions().size());
    assertEquals(0L, actual.getCookie().getValue());
    assertEquals(0L, actual.getCookieMask().getValue());
    assertEquals(testPriority, actual.getPriority());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 15 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithTransitVlanEncapsulation.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithTransitVlanEncapsulation() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String inVlan = "10";
    String outPort = "2";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, inVlan, outPort, null, false, null, null);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertEquals(Integer.valueOf(inVlan), criteria.getEncapsulationId());
    assertEquals(Integer.valueOf(outPort), criteria.getOutPort());
    assertNull(criteria.getMetadataValue());
    assertNull(criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Aggregations

DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)17 Test (org.junit.Test)13 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)10 EasyMock.anyLong (org.easymock.EasyMock.anyLong)9 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)3 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)3 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)3 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)3 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)3 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayList (java.util.ArrayList)2 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)2 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1