Search in sources :

Example 1 with EthType

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

the class OfMatchConverter method getMasked.

private FieldMatch getMasked(Match match, MatchField<?> field) {
    FieldMatchBuilder builder = FieldMatch.builder();
    switch(field.id) {
        case ETH_SRC:
            Masked<MacAddress> ethSrcMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.ETH_SRC);
            builder.field(Field.ETH_SRC);
            builder.value(ethSrcMasked.getValue().getLong());
            builder.mask(ethSrcMasked.getMask().getLong());
            break;
        case ETH_DST:
            Masked<MacAddress> ethDstMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.ETH_DST);
            builder.field(Field.ETH_DST);
            builder.value(ethDstMasked.getValue().getLong());
            builder.mask(ethDstMasked.getMask().getLong());
            break;
        case ETH_TYPE:
            Masked<EthType> ethTypeMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.ETH_TYPE);
            builder.field(Field.ETH_TYPE);
            builder.value(ethTypeMasked.getValue().getValue());
            builder.mask((long) ethTypeMasked.getMask().getValue());
            break;
        case IP_PROTO:
            Masked<IpProtocol> ipProtocolMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.IP_PROTO);
            builder.field(Field.IP_PROTO);
            builder.value(ipProtocolMasked.getValue().getIpProtocolNumber());
            builder.mask((long) ipProtocolMasked.getMask().getIpProtocolNumber());
            break;
        case UDP_SRC:
            Masked<TransportPort> udpSrcMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.UDP_SRC);
            builder.field(Field.UDP_SRC);
            builder.value(udpSrcMasked.getValue().getPort());
            builder.mask((long) udpSrcMasked.getMask().getPort());
            break;
        case UDP_DST:
            Masked<TransportPort> udpDstMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.UDP_DST);
            builder.field(Field.UDP_DST);
            builder.value(udpDstMasked.getValue().getPort());
            builder.mask((long) udpDstMasked.getMask().getPort());
            break;
        case METADATA:
            Masked<OFMetadata> metadataMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.METADATA);
            builder.field(Field.METADATA);
            builder.value(metadataMasked.getValue().getValue().getValue());
            builder.mask(metadataMasked.getMask().getValue().getValue());
            break;
        case IN_PORT:
            Masked<OFPort> inPortMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.IN_PORT);
            builder.field(Field.IN_PORT);
            builder.value(inPortMasked.getValue().getPortNumber());
            builder.mask((long) inPortMasked.getMask().getPortNumber());
            break;
        case VLAN_VID:
            Masked<OFVlanVidMatch> vlanVidMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.VLAN_VID);
            builder.field(Field.VLAN_VID);
            builder.value(vlanVidMasked.getValue().getVlan());
            builder.mask((long) vlanVidMasked.getMask().getVlan());
            break;
        case TUNNEL_ID:
            Masked<U64> tunnelIdMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.TUNNEL_ID);
            builder.field(Field.NOVIFLOW_TUNNEL_ID);
            builder.value(tunnelIdMasked.getValue().getValue());
            builder.mask(tunnelIdMasked.getMask().getValue());
            break;
        case KILDA_VXLAN_VNI:
            Masked<U32> masked = match.getMaskedWithoutPrerequisitesCheck(MatchField.KILDA_VXLAN_VNI);
            builder.field(Field.OVS_VXLAN_VNI);
            builder.value(masked.getValue().getValue());
            builder.mask(masked.getMask().getValue());
            break;
        default:
            throw new IllegalArgumentException(String.format("Unexpected match field id=%s, for class=%s of a match %s", field.id, field.getClass().getName(), match));
    }
    return builder.build();
}
Also used : OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) MacAddress(org.projectfloodlight.openflow.types.MacAddress) OFMetadata(org.projectfloodlight.openflow.types.OFMetadata) FieldMatchBuilder(org.openkilda.rulemanager.match.FieldMatch.FieldMatchBuilder) EthType(org.projectfloodlight.openflow.types.EthType) U64(org.projectfloodlight.openflow.types.U64) U32(org.projectfloodlight.openflow.types.U32) OFPort(org.projectfloodlight.openflow.types.OFPort) IpProtocol(org.projectfloodlight.openflow.types.IpProtocol) TransportPort(org.projectfloodlight.openflow.types.TransportPort)

Example 2 with EthType

use of org.projectfloodlight.openflow.types.EthType 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);
}
Also used : OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) MacAddress(org.projectfloodlight.openflow.types.MacAddress) OFMetadata(org.projectfloodlight.openflow.types.OFMetadata) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) EthType(org.projectfloodlight.openflow.types.EthType) U64(org.projectfloodlight.openflow.types.U64) U32(org.projectfloodlight.openflow.types.U32) OFPort(org.projectfloodlight.openflow.types.OFPort) IpProtocol(org.projectfloodlight.openflow.types.IpProtocol) TransportPort(org.projectfloodlight.openflow.types.TransportPort) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with EthType

use of org.projectfloodlight.openflow.types.EthType 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());
}
Also used : OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) MacAddress(org.projectfloodlight.openflow.types.MacAddress) OFMetadata(org.projectfloodlight.openflow.types.OFMetadata) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) EthType(org.projectfloodlight.openflow.types.EthType) U64(org.projectfloodlight.openflow.types.U64) OFPort(org.projectfloodlight.openflow.types.OFPort) IpProtocol(org.projectfloodlight.openflow.types.IpProtocol) TransportPort(org.projectfloodlight.openflow.types.TransportPort) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

EthType (org.projectfloodlight.openflow.types.EthType)3 IpProtocol (org.projectfloodlight.openflow.types.IpProtocol)3 MacAddress (org.projectfloodlight.openflow.types.MacAddress)3 OFMetadata (org.projectfloodlight.openflow.types.OFMetadata)3 OFPort (org.projectfloodlight.openflow.types.OFPort)3 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)3 TransportPort (org.projectfloodlight.openflow.types.TransportPort)3 U64 (org.projectfloodlight.openflow.types.U64)3 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)2 Match (org.projectfloodlight.openflow.protocol.match.Match)2 OFFactoryVer13 (org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13)2 U32 (org.projectfloodlight.openflow.types.U32)2 FieldMatchBuilder (org.openkilda.rulemanager.match.FieldMatch.FieldMatchBuilder)1