Search in sources :

Example 71 with FieldMatch

use of org.openkilda.rulemanager.match.FieldMatch in project open-kilda by telstra.

the class MultiTableIngressRuleGeneratorTest method buildCommandsVlanEncapsulationDoubleVlanPortOverlappingTest.

@Test
public void buildCommandsVlanEncapsulationDoubleVlanPortOverlappingTest() {
    Flow oneSwitchFlow = buildFlow(ONE_SWITCH_PATH, OUTER_VLAN_ID_2, 0);
    Set<FlowSideAdapter> overlapping = Sets.newHashSet(FlowSideAdapter.makeIngressAdapter(oneSwitchFlow, ONE_SWITCH_PATH));
    Flow flow = buildFlow(PATH, OUTER_VLAN_ID_1, INNER_VLAN_ID_1);
    MultiTableIngressRuleGenerator generator = buildGenerator(PATH, flow, VLAN_ENCAPSULATION, overlapping);
    List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
    assertEquals(3, commands.size());
    FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
    FlowSpeakerData preIngressCommand = (FlowSpeakerData) commands.get(1);
    MeterSpeakerData meterCommand = (MeterSpeakerData) commands.get(2);
    assertEquals(newArrayList(meterCommand.getUuid()), new ArrayList<>(ingressCommand.getDependsOn()));
    RoutingMetadata ingressMetadata = RoutingMetadata.builder().outerVlanId(OUTER_VLAN_ID_1).build(SWITCH_1.getFeatures());
    Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(INNER_VLAN_ID_1).build(), FieldMatch.builder().field(Field.METADATA).value(ingressMetadata.getValue()).mask(ingressMetadata.getMask()).build());
    List<Action> expectedIngressActions = newArrayList(SetFieldAction.builder().field(Field.VLAN_VID).value(TRANSIT_VLAN_ID).build(), new PortOutAction(new PortNumber(PORT_NUMBER_2)));
    Set<FieldMatch> expectedPreIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_1).build());
    FlowSharedSegmentCookie preIngressCookie = FlowSharedSegmentCookie.builder(SharedSegmentType.QINQ_OUTER_VLAN).portNumber(PORT_NUMBER_1).vlanId(OUTER_VLAN_ID_1).build();
    RoutingMetadata preIngressMetadata = RoutingMetadata.builder().outerVlanId(OUTER_VLAN_ID_1).build(SWITCH_1.getFeatures());
    assertPreIngressCommand(preIngressCommand, preIngressCookie, Priority.FLOW_PRIORITY, expectedPreIngressMatch, newArrayList(new PopVlanAction()), mapMetadata(preIngressMetadata));
    assertIngressCommand(ingressCommand, Priority.DOUBLE_VLAN_FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions, METER_ID, null);
    assertMeterCommand(meterCommand);
}
Also used : SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) RoutingMetadata(org.openkilda.rulemanager.utils.RoutingMetadata) Flow(org.openkilda.model.Flow) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 72 with FieldMatch

use of org.openkilda.rulemanager.match.FieldMatch in project open-kilda by telstra.

the class Server42IslRttTurningRuleGeneratorTest method server42IslRttTurningRuleGeneratorTest.

@Test
public void server42IslRttTurningRuleGeneratorTest() {
    Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new Cookie(SERVER_42_ISL_RTT_TURNING_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(SERVER_42_ISL_RTT_TURNING_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(MAC_ADDRESS.toLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_FORWARD_UDP_PORT).build());
    assertEquals(expectedMatch, flowCommandData.getMatch());
    List<Action> expectedApplyActions = Lists.newArrayList(SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_REVERSE_UDP_PORT).build(), new PortOutAction(new PortNumber(SpecialPortType.IN_PORT)));
    Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Utils.buildSwitch(org.openkilda.rulemanager.Utils.buildSwitch) Switch(org.openkilda.model.Switch) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 73 with FieldMatch

use of org.openkilda.rulemanager.match.FieldMatch in project open-kilda by telstra.

the class OfMatchConverterTest method testConvertToRuleManagerMatchExact.

@Test
public void testConvertToRuleManagerMatchExact() {
    OFFactoryVer13 factory = new OFFactoryVer13();
    Match match = factory.buildMatch().setExact(MatchField.ETH_TYPE, EthType.IPv4).setExact(MatchField.ETH_SRC, MacAddress.of(1)).setExact(MatchField.ETH_DST, MacAddress.of(2)).setExact(MatchField.IP_PROTO, IpProtocol.of((short) 17)).setExact(MatchField.UDP_SRC, TransportPort.of(11)).setExact(MatchField.UDP_DST, TransportPort.of(22)).setExact(MatchField.METADATA, OFMetadata.of(U64.of(333))).setExact(MatchField.IN_PORT, OFPort.of(12)).setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(444)).setExact(MatchField.TUNNEL_ID, U64.of(555)).setExact(MatchField.KILDA_VXLAN_VNI, U32.of(666)).build();
    Set<FieldMatch> expectedMatches = new HashSet<>();
    expectedMatches.add(FieldMatch.builder().value(2048).field(Field.ETH_TYPE).build());
    expectedMatches.add(FieldMatch.builder().value(1).field(Field.ETH_SRC).build());
    expectedMatches.add(FieldMatch.builder().value(2).field(Field.ETH_DST).build());
    expectedMatches.add(FieldMatch.builder().value(17).field(Field.IP_PROTO).build());
    expectedMatches.add(FieldMatch.builder().value(11).field(Field.UDP_SRC).build());
    expectedMatches.add(FieldMatch.builder().value(22).field(Field.UDP_DST).build());
    expectedMatches.add(FieldMatch.builder().value(333).field(Field.METADATA).build());
    expectedMatches.add(FieldMatch.builder().value(12).field(Field.IN_PORT).build());
    expectedMatches.add(FieldMatch.builder().value(444).field(Field.VLAN_VID).build());
    expectedMatches.add(FieldMatch.builder().value(555).field(Field.NOVIFLOW_TUNNEL_ID).build());
    expectedMatches.add(FieldMatch.builder().value(666).field(Field.OVS_VXLAN_VNI).build());
    Set<FieldMatch> fieldMatches = OfMatchConverter.INSTANCE.convertToRuleManagerMatch(match);
    assertEquals(expectedMatches, fieldMatches);
}
Also used : OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 74 with FieldMatch

use of org.openkilda.rulemanager.match.FieldMatch in project open-kilda by telstra.

the class OfMatchConverterTest method testConvertToRuleManagerMatchMasked.

@Test
public void testConvertToRuleManagerMatchMasked() {
    OFFactoryVer13 factory = new OFFactoryVer13();
    Match match = factory.buildMatch().setMasked(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv4).setMasked(MatchField.ETH_SRC, MacAddress.of(1), MacAddress.of(1)).setMasked(MatchField.ETH_DST, MacAddress.of(2), MacAddress.of(2)).setMasked(MatchField.IP_PROTO, IpProtocol.of((short) 17), IpProtocol.of((short) 17)).setMasked(MatchField.UDP_SRC, TransportPort.of(11), TransportPort.of(11)).setMasked(MatchField.UDP_DST, TransportPort.of(22), TransportPort.of(22)).setMasked(MatchField.METADATA, OFMetadata.of(U64.of(333)), OFMetadata.of(U64.of(333))).setMasked(MatchField.IN_PORT, OFPort.of(12), OFPort.of(12)).setMasked(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(444), OFVlanVidMatch.ofVlan(444)).setMasked(MatchField.TUNNEL_ID, U64.of(555), U64.of(555)).build();
    Set<FieldMatch> expectedMatches = new HashSet<>();
    expectedMatches.add(FieldMatch.builder().value(2048).mask(2048L).field(Field.ETH_TYPE).build());
    expectedMatches.add(FieldMatch.builder().value(1).mask(1L).field(Field.ETH_SRC).build());
    expectedMatches.add(FieldMatch.builder().value(2).mask(2L).field(Field.ETH_DST).build());
    expectedMatches.add(FieldMatch.builder().value(17).mask(17L).field(Field.IP_PROTO).build());
    expectedMatches.add(FieldMatch.builder().value(11).mask(11L).field(Field.UDP_SRC).build());
    expectedMatches.add(FieldMatch.builder().value(22).mask(22L).field(Field.UDP_DST).build());
    expectedMatches.add(FieldMatch.builder().value(333).mask(333L).field(Field.METADATA).build());
    expectedMatches.add(FieldMatch.builder().value(12).mask(12L).field(Field.IN_PORT).build());
    expectedMatches.add(FieldMatch.builder().value(444).mask(444L).field(Field.VLAN_VID).build());
    expectedMatches.add(FieldMatch.builder().value(555).mask(555L).field(Field.NOVIFLOW_TUNNEL_ID).build());
    Set<FieldMatch> fieldMatches = OfMatchConverter.INSTANCE.convertToRuleManagerMatch(match);
    assertEquals(expectedMatches, fieldMatches);
}
Also used : OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 75 with FieldMatch

use of org.openkilda.rulemanager.match.FieldMatch in project open-kilda by telstra.

the class ArpInputPreDropRuleGeneratorTest method checkMatch.

@Override
protected void checkMatch(Set<FieldMatch> match) {
    assertEquals(1, match.size());
    FieldMatch ethTypeMatch = getMatchByField(Field.ETH_TYPE, match);
    assertEquals(EthType.ARP, ethTypeMatch.getValue());
    assertFalse(ethTypeMatch.isMasked());
}
Also used : FieldMatch(org.openkilda.rulemanager.match.FieldMatch)

Aggregations

FieldMatch (org.openkilda.rulemanager.match.FieldMatch)121 Test (org.junit.Test)61 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)55 Instructions (org.openkilda.rulemanager.Instructions)55 SpeakerData (org.openkilda.rulemanager.SpeakerData)50 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)50 Action (org.openkilda.rulemanager.action.Action)46 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)41 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)41 RoutingMetadata (org.openkilda.rulemanager.utils.RoutingMetadata)37 Flow (org.openkilda.model.Flow)31 Cookie (org.openkilda.model.cookie.Cookie)30 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)27 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)25 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)24 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)23 PortColourCookie (org.openkilda.model.cookie.PortColourCookie)15 FlowSourceAdapter (org.openkilda.adapter.FlowSourceAdapter)12 Switch (org.openkilda.model.Switch)12 GroupSpeakerData (org.openkilda.rulemanager.GroupSpeakerData)12