Search in sources :

Example 36 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class BgpUpdateMsgTest method bgpUpdateMessageTest41.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrIGPFlags.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest41() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x93, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x78, // origin
    0x04, // origin
    0x01, // origin
    0x01, // origin
    0x00, // as_path
    0x40, // as_path
    0x02, // as_path
    0x04, // as_path
    0x02, // as_path
    0x01, // as_path
    (byte) 0xfd, // as_path
    (byte) 0xe9, // med
    (byte) 0x80, // med
    0x04, // med
    0x04, // med
    0x00, // med
    0x00, // med
    0x00, // med
    0x00, // mpreach
    (byte) 0x80, // mpreach
    0x0e, // mpreach
    0x53, // mpreach
    0x40, // mpreach
    0x04, // mpreach
    0x47, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
    0x00, // link nlri
    (byte) 0x95, // link nlri
    0x02, // link nlri
    0x50, // link nlri
    0x21, // linkstate attr
    (byte) 0x80, // linkstate attr
    0x1d, // linkstate attr
    0x0D, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x00, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    (byte) 0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, 0x04, (byte) 0x80, 0x00, 0x01, // BgpPrefixAttrIGPFlags
    (byte) 0xA0 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;
    byte[] marker = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
    assertThat(other.getHeader().getMarker(), is(marker));
    assertThat(other.getHeader().getType(), is((byte) 2));
    assertThat(other.getHeader().getLength(), is((short) 147));
    BgpValueType testPathAttribute = null;
    Origin origin;
    AsPath aspath;
    Med med;
    MpReachNlri mpReach;
    LinkStateAttributes linkStateAttr;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    BgpPathAttributes pathAttribute = other.bgpPathAttributes();
    pathAttributeList = pathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
    OriginType originValue = OriginType.IGP;
    testPathAttribute = listIterator.next();
    origin = (Origin) testPathAttribute;
    assertThat(origin.origin(), is(originValue));
    testPathAttribute = listIterator.next();
    aspath = (AsPath) testPathAttribute;
    ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
    assertThat(listIterator2.next(), is((short) 65001));
    testPathAttribute = listIterator.next();
    med = (Med) testPathAttribute;
    assertThat(med.med(), is(0));
    testPathAttribute = listIterator.next();
    mpReach = (MpReachNlri) testPathAttribute;
    List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
    testMpReachNlri = mpReach.mpReachNlri();
    ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
    BgpLSNlri testnlri = list1.next();
    NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
    ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
    assertThat(testnlri.getIdentifier(), is((long) 0));
    assertThat(testnlri.getNlriType(), is(nlriType));
    assertThat(testnlri.getProtocolId(), is(protocolId));
    testPathAttribute = listIterator.next();
    linkStateAttr = (LinkStateAttributes) testPathAttribute;
    assertThat(linkStateAttr.getType(), is((short) 29));
    ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
    byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
    Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
    assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
    BgpPrefixAttrIgpFlags obj = new BgpPrefixAttrIgpFlags(true, false, true, false);
    assertThat(((BgpPrefixAttrIgpFlags) list.next()).equals(obj), is(true));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) Ip4Address(org.onlab.packet.Ip4Address) BgpHeader(org.onosproject.bgpio.types.BgpHeader) BgpPrefixAttrIgpFlags(org.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) BgpValueType(org.onosproject.bgpio.types.BgpValueType) OriginType(org.onosproject.bgpio.types.Origin.OriginType) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 37 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class BgpUpdateMsgTest method bgpUpdateMessageTest40.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrName.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest40() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x7F, // origin
    0x04, // origin
    0x01, // origin
    0x01, // origin
    0x00, // as_path
    0x40, // as_path
    0x02, // as_path
    0x04, // as_path
    0x02, // as_path
    0x01, // as_path
    (byte) 0xfd, // as_path
    (byte) 0xe9, // med
    (byte) 0x80, // med
    0x04, // med
    0x04, // med
    0x00, // med
    0x00, // med
    0x00, // med
    0x00, // mpreach
    (byte) 0x80, // mpreach
    0x0e, // mpreach
    0x53, // mpreach
    0x40, // mpreach
    0x04, // mpreach
    0x47, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
    0x00, // link nlri
    (byte) 0x95, // link nlri
    0x02, // link nlri
    0x50, // link nlri
    0x21, // linkstate attr
    (byte) 0x80, // linkstate attr
    0x1d, // linkstate attr
    0x14, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x00, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    (byte) 0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, 0x04, 0x4A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, // BgpLinkAttrName
    0x0b };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;
    byte[] marker = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
    assertThat(other.getHeader().getMarker(), is(marker));
    assertThat(other.getHeader().getType(), is((byte) 2));
    assertThat(other.getHeader().getLength(), is((short) 154));
    ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
    byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
    while (listIterator1.hasNext()) {
        IpPrefix testPrefixValue = listIterator1.next();
        assertThat(testPrefixValue.prefixLength(), is((int) 24));
        assertThat(testPrefixValue.address().toOctets(), is(prefix));
    }
    BgpValueType testPathAttribute = null;
    Origin origin;
    AsPath aspath;
    Med med;
    MpReachNlri mpReach;
    LinkStateAttributes linkStateAttr;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    BgpPathAttributes pathAttribute = other.bgpPathAttributes();
    pathAttributeList = pathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
    OriginType originValue = OriginType.IGP;
    testPathAttribute = listIterator.next();
    origin = (Origin) testPathAttribute;
    assertThat(origin.origin(), is(originValue));
    testPathAttribute = listIterator.next();
    aspath = (AsPath) testPathAttribute;
    ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
    assertThat(listIterator2.next(), is((short) 65001));
    testPathAttribute = listIterator.next();
    med = (Med) testPathAttribute;
    assertThat(med.med(), is(0));
    testPathAttribute = listIterator.next();
    mpReach = (MpReachNlri) testPathAttribute;
    assertThat(mpReach.mpReachNlriLen(), is((int) 83));
    assertThat(mpReach.getType(), is((short) 14));
    List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
    testMpReachNlri = mpReach.mpReachNlri();
    ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
    BgpLSNlri testnlri = list1.next();
    NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
    ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
    assertThat(testnlri.getIdentifier(), is((long) 0));
    assertThat(testnlri.getNlriType(), is(nlriType));
    assertThat(testnlri.getProtocolId(), is(protocolId));
    testPathAttribute = listIterator.next();
    linkStateAttr = (LinkStateAttributes) testPathAttribute;
    assertThat(linkStateAttr.getType(), is((short) 29));
    ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
    byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
    Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
    assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
    byte[] linkName = new byte[] { 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b };
    assertThat(((BgpLinkAttrName) list.next()).attrLinkName(), is(linkName));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) Ip4Address(org.onlab.packet.Ip4Address) BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) BgpValueType(org.onosproject.bgpio.types.BgpValueType) OriginType(org.onosproject.bgpio.types.Origin.OriginType) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 38 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class FlowModBuilder method buildMatch.

/**
 * Builds the match for the flow mod.
 *
 * @return the match
 */
// CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
protected Match buildMatch() {
    Match.Builder mBuilder = factory.buildMatch();
    Ip6Address ip6Address;
    Ip4Prefix ip4Prefix;
    Ip6Prefix ip6Prefix;
    EthCriterion ethCriterion;
    IPCriterion ipCriterion;
    TcpPortCriterion tcpPortCriterion;
    UdpPortCriterion udpPortCriterion;
    SctpPortCriterion sctpPortCriterion;
    IPv6NDLinkLayerAddressCriterion llAddressCriterion;
    ArpHaCriterion arpHaCriterion;
    ArpPaCriterion arpPaCriterion;
    for (Criterion c : selector.criteria()) {
        switch(c.type()) {
            case IN_PORT:
                PortCriterion inPort = (PortCriterion) c;
                mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inPort.port().toLong()));
                break;
            case IN_PHY_PORT:
                PortCriterion inPhyPort = (PortCriterion) c;
                mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inPhyPort.port().toLong()));
                break;
            case METADATA:
                MetadataCriterion metadata = (MetadataCriterion) c;
                mBuilder.setExact(MatchField.METADATA, OFMetadata.ofRaw(metadata.metadata()));
                break;
            case ETH_DST:
                ethCriterion = (EthCriterion) c;
                mBuilder.setExact(MatchField.ETH_DST, MacAddress.of(ethCriterion.mac().toLong()));
                break;
            case ETH_DST_MASKED:
                ethCriterion = (EthCriterion) c;
                mBuilder.setMasked(MatchField.ETH_DST, MacAddress.of(ethCriterion.mac().toLong()), MacAddress.of(ethCriterion.mask().toLong()));
                break;
            case ETH_SRC:
                ethCriterion = (EthCriterion) c;
                mBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(ethCriterion.mac().toLong()));
                break;
            case ETH_SRC_MASKED:
                ethCriterion = (EthCriterion) c;
                mBuilder.setMasked(MatchField.ETH_SRC, MacAddress.of(ethCriterion.mac().toLong()), MacAddress.of(ethCriterion.mask().toLong()));
                break;
            case ETH_TYPE:
                EthTypeCriterion ethType = (EthTypeCriterion) c;
                mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
                break;
            case VLAN_VID:
                VlanIdCriterion vid = (VlanIdCriterion) c;
                if (vid.vlanId().equals(VlanId.ANY)) {
                    mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
                } else if (vid.vlanId().equals(VlanId.NONE)) {
                    mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE);
                } else {
                    mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
                }
                break;
            case VLAN_PCP:
                VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
                mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
                break;
            case IP_DSCP:
                IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
                mBuilder.setExact(MatchField.IP_DSCP, IpDscp.of(ipDscpCriterion.ipDscp()));
                break;
            case IP_ECN:
                IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
                mBuilder.setExact(MatchField.IP_ECN, IpEcn.of(ipEcnCriterion.ipEcn()));
                break;
            case IP_PROTO:
                IPProtocolCriterion p = (IPProtocolCriterion) c;
                mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
                break;
            case IPV4_SRC:
                ipCriterion = (IPCriterion) c;
                ip4Prefix = ipCriterion.ip().getIp4Prefix();
                if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
                    Ip4Address maskAddr = Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
                    Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), IPv4Address.of(maskAddr.toInt()));
                    mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV4_SRC, IPv4Address.of(ip4Prefix.address().toInt()));
                }
                break;
            case IPV4_DST:
                ipCriterion = (IPCriterion) c;
                ip4Prefix = ipCriterion.ip().getIp4Prefix();
                if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
                    Ip4Address maskAddr = Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
                    Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), IPv4Address.of(maskAddr.toInt()));
                    mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV4_DST, IPv4Address.of(ip4Prefix.address().toInt()));
                }
                break;
            case TCP_SRC:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setExact(MatchField.TCP_SRC, TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
                break;
            case TCP_SRC_MASKED:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setMasked(MatchField.TCP_SRC, TransportPort.of(tcpPortCriterion.tcpPort().toInt()), TransportPort.of(tcpPortCriterion.mask().toInt()));
                break;
            case TCP_DST:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setExact(MatchField.TCP_DST, TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
                break;
            case TCP_DST_MASKED:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setMasked(MatchField.TCP_DST, TransportPort.of(tcpPortCriterion.tcpPort().toInt()), TransportPort.of(tcpPortCriterion.mask().toInt()));
                break;
            case UDP_SRC:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setExact(MatchField.UDP_SRC, TransportPort.of(udpPortCriterion.udpPort().toInt()));
                break;
            case UDP_SRC_MASKED:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setMasked(MatchField.UDP_SRC, TransportPort.of(udpPortCriterion.udpPort().toInt()), TransportPort.of(udpPortCriterion.mask().toInt()));
                break;
            case UDP_DST:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setExact(MatchField.UDP_DST, TransportPort.of(udpPortCriterion.udpPort().toInt()));
                break;
            case UDP_DST_MASKED:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setMasked(MatchField.UDP_DST, TransportPort.of(udpPortCriterion.udpPort().toInt()), TransportPort.of(udpPortCriterion.mask().toInt()));
                break;
            case SCTP_SRC:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setExact(MatchField.SCTP_SRC, TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
                break;
            case SCTP_SRC_MASKED:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setMasked(MatchField.SCTP_SRC, TransportPort.of(sctpPortCriterion.sctpPort().toInt()), TransportPort.of(sctpPortCriterion.mask().toInt()));
                break;
            case SCTP_DST:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setExact(MatchField.SCTP_DST, TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
                break;
            case SCTP_DST_MASKED:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setMasked(MatchField.SCTP_DST, TransportPort.of(sctpPortCriterion.sctpPort().toInt()), TransportPort.of(sctpPortCriterion.mask().toInt()));
                break;
            case ICMPV4_TYPE:
                IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV4_TYPE, ICMPv4Type.of(icmpType.icmpType()));
                break;
            case ICMPV4_CODE:
                IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV4_CODE, ICMPv4Code.of(icmpCode.icmpCode()));
                break;
            case IPV6_SRC:
                ipCriterion = (IPCriterion) c;
                ip6Prefix = ipCriterion.ip().getIp6Prefix();
                if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
                    Ip6Address maskAddr = Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
                    Masked<IPv6Address> maskedIp = Masked.of(IPv6Address.of(ip6Prefix.address().toString()), IPv6Address.of(maskAddr.toString()));
                    mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV6_SRC, IPv6Address.of(ip6Prefix.address().toString()));
                }
                break;
            case IPV6_DST:
                ipCriterion = (IPCriterion) c;
                ip6Prefix = ipCriterion.ip().getIp6Prefix();
                if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
                    Ip6Address maskAddr = Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
                    Masked<IPv6Address> maskedIp = Masked.of(IPv6Address.of(ip6Prefix.address().toString()), IPv6Address.of(maskAddr.toString()));
                    mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV6_DST, IPv6Address.of(ip6Prefix.address().toString()));
                }
                break;
            case IPV6_FLABEL:
                IPv6FlowLabelCriterion flowLabelCriterion = (IPv6FlowLabelCriterion) c;
                mBuilder.setExact(MatchField.IPV6_FLABEL, IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
                break;
            case ICMPV6_TYPE:
                Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV6_TYPE, U8.of(icmpv6Type.icmpv6Type()));
                break;
            case ICMPV6_CODE:
                Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV6_CODE, U8.of(icmpv6Code.icmpv6Code()));
                break;
            case IPV6_ND_TARGET:
                IPv6NDTargetAddressCriterion targetAddressCriterion = (IPv6NDTargetAddressCriterion) c;
                ip6Address = targetAddressCriterion.targetAddress();
                mBuilder.setExact(MatchField.IPV6_ND_TARGET, IPv6Address.of(ip6Address.toOctets()));
                break;
            case IPV6_ND_SLL:
                llAddressCriterion = (IPv6NDLinkLayerAddressCriterion) c;
                mBuilder.setExact(MatchField.IPV6_ND_SLL, MacAddress.of(llAddressCriterion.mac().toLong()));
                break;
            case IPV6_ND_TLL:
                llAddressCriterion = (IPv6NDLinkLayerAddressCriterion) c;
                mBuilder.setExact(MatchField.IPV6_ND_TLL, MacAddress.of(llAddressCriterion.mac().toLong()));
                break;
            case MPLS_LABEL:
                MplsCriterion mp = (MplsCriterion) c;
                mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
                break;
            case IPV6_EXTHDR:
                IPv6ExthdrFlagsCriterion exthdrFlagsCriterion = (IPv6ExthdrFlagsCriterion) c;
                mBuilder.setExact(MatchField.IPV6_EXTHDR, U16.of(exthdrFlagsCriterion.exthdrFlags()));
                break;
            case OCH_SIGID:
                try {
                    OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
                    OchSignal signal = ochSignalCriterion.lambda();
                    byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
                    byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
                    mBuilder.setExact(MatchField.EXP_OCH_SIG_ID, new CircuitSignalID(gridType, channelSpacing, (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                }
                break;
            case OCH_SIGTYPE:
                try {
                    OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
                    byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
                    mBuilder.setExact(MatchField.EXP_OCH_SIGTYPE, U8.of(signalType));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                }
                break;
            case ODU_SIGID:
                OduSignalIdCriterion oduSignalIdCriterion = (OduSignalIdCriterion) c;
                OduSignalId oduSignalId = oduSignalIdCriterion.oduSignalId();
                mBuilder.setExact(MatchField.EXP_ODU_SIG_ID, new OduSignalID((short) oduSignalId.tributaryPortNumber(), (short) oduSignalId.tributarySlotLength(), oduSignalId.tributarySlotBitmap()));
                break;
            case ODU_SIGTYPE:
                try {
                    OduSignalTypeCriterion oduSignalTypeCriterion = (OduSignalTypeCriterion) c;
                    byte oduSigType = OpenFlowValueMapper.lookupOduSignalType(oduSignalTypeCriterion.signalType());
                    mBuilder.setExact(MatchField.EXP_ODU_SIGTYPE, U8.of(oduSigType));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                }
                break;
            case TUNNEL_ID:
                TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
                mBuilder.setExact(MatchField.TUNNEL_ID, U64.of(tunnelId.tunnelId()));
                break;
            case MPLS_BOS:
                MplsBosCriterion mplsBos = (MplsBosCriterion) c;
                mBuilder.setExact(MatchField.MPLS_BOS, mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE);
                break;
            case ARP_OP:
                ArpOpCriterion arpOp = (ArpOpCriterion) c;
                mBuilder.setExact(MatchField.ARP_OP, ArpOpcode.of(arpOp.arpOp()));
                break;
            case ARP_SHA:
                arpHaCriterion = (ArpHaCriterion) c;
                mBuilder.setExact(MatchField.ARP_SHA, MacAddress.of(arpHaCriterion.mac().toLong()));
                break;
            case ARP_SPA:
                arpPaCriterion = (ArpPaCriterion) c;
                mBuilder.setExact(MatchField.ARP_SPA, IPv4Address.of(arpPaCriterion.ip().toInt()));
                break;
            case ARP_THA:
                arpHaCriterion = (ArpHaCriterion) c;
                mBuilder.setExact(MatchField.ARP_THA, MacAddress.of(arpHaCriterion.mac().toLong()));
                break;
            case ARP_TPA:
                arpPaCriterion = (ArpPaCriterion) c;
                mBuilder.setExact(MatchField.ARP_TPA, IPv4Address.of(arpPaCriterion.ip().toInt()));
                break;
            case EXTENSION:
                ExtensionCriterion extensionCriterion = (ExtensionCriterion) c;
                OFOxm oxm = buildExtensionOxm(extensionCriterion.extensionSelector());
                if (oxm == null) {
                    log.warn("Unable to build extension selector");
                    break;
                }
                if (oxm.isMasked()) {
                    mBuilder.setMasked(oxm.getMatchField(), oxm.getValue(), oxm.getMask());
                } else {
                    mBuilder.setExact(oxm.getMatchField(), oxm.getValue());
                }
                break;
            case MPLS_TC:
            case PBB_ISID:
            // TODO: need to implement PBB-ISID case when OpenFlowJ is ready
            default:
                log.warn("Match type {} not yet implemented.", c.type());
        }
    }
    return mBuilder.build();
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Ip4Address(org.onlab.packet.Ip4Address) IPv6Address(org.projectfloodlight.openflow.types.IPv6Address) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) Ip6Address(org.onlab.packet.Ip6Address) IcmpCodeCriterion(org.onosproject.net.flow.criteria.IcmpCodeCriterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) CircuitSignalID(org.projectfloodlight.openflow.types.CircuitSignalID) ArpHaCriterion(org.onosproject.net.flow.criteria.ArpHaCriterion) IcmpTypeCriterion(org.onosproject.net.flow.criteria.IcmpTypeCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) IPv6NDTargetAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) OFOxm(org.projectfloodlight.openflow.protocol.oxm.OFOxm) IPDscpCriterion(org.onosproject.net.flow.criteria.IPDscpCriterion) NoMappingFoundException(org.onosproject.provider.of.flow.util.NoMappingFoundException) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) IPv6ExthdrFlagsCriterion(org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) Ip6Prefix(org.onlab.packet.Ip6Prefix) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) IPDscpCriterion(org.onosproject.net.flow.criteria.IPDscpCriterion) ArpHaCriterion(org.onosproject.net.flow.criteria.ArpHaCriterion) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IcmpTypeCriterion(org.onosproject.net.flow.criteria.IcmpTypeCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) ExtensionCriterion(org.onosproject.net.flow.criteria.ExtensionCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) IcmpCodeCriterion(org.onosproject.net.flow.criteria.IcmpCodeCriterion) IPv6NDTargetAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) ArpOpCriterion(org.onosproject.net.flow.criteria.ArpOpCriterion) ArpPaCriterion(org.onosproject.net.flow.criteria.ArpPaCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) IPv6NDLinkLayerAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPEcnCriterion(org.onosproject.net.flow.criteria.IPEcnCriterion) OduSignalTypeCriterion(org.onosproject.net.flow.criteria.OduSignalTypeCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) OchSignalTypeCriterion(org.onosproject.net.flow.criteria.OchSignalTypeCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) IPv6ExthdrFlagsCriterion(org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) OduSignalId(org.onosproject.net.OduSignalId) IPEcnCriterion(org.onosproject.net.flow.criteria.IPEcnCriterion) OchSignalTypeCriterion(org.onosproject.net.flow.criteria.OchSignalTypeCriterion) OduSignalTypeCriterion(org.onosproject.net.flow.criteria.OduSignalTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) OchSignal(org.onosproject.net.OchSignal) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) ArpOpCriterion(org.onosproject.net.flow.criteria.ArpOpCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) ExtensionCriterion(org.onosproject.net.flow.criteria.ExtensionCriterion) ArpPaCriterion(org.onosproject.net.flow.criteria.ArpPaCriterion) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) IPv6NDLinkLayerAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Ip4Prefix(org.onlab.packet.Ip4Prefix) OduSignalID(org.projectfloodlight.openflow.types.OduSignalID)

Example 39 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class FlowEntryBuilder method buildSelector.

// CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
private TrafficSelector buildSelector() {
    MacAddress mac;
    Ip4Prefix ip4Prefix;
    Ip6Address ip6Address;
    Ip6Prefix ip6Prefix;
    Ip4Address ip;
    ExtensionSelectorInterpreter selectorInterpreter;
    if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
        selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
    } else {
        selectorInterpreter = null;
    }
    TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
    for (MatchField<?> field : match.getMatchFields()) {
        switch(field.id) {
            case IN_PORT:
                builder.matchInPort(PortNumber.portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
                break;
            case IN_PHY_PORT:
                builder.matchInPhyPort(PortNumber.portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
                break;
            case METADATA:
                long metadata = match.get(MatchField.METADATA).getValue().getValue();
                builder.matchMetadata(metadata);
                break;
            case ETH_DST:
                if (match.isPartiallyMasked(MatchField.ETH_DST)) {
                    Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = match.getMasked(MatchField.ETH_DST);
                    builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), MacAddress.valueOf(maskedMac.getMask().getLong()));
                } else {
                    mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
                    builder.matchEthDst(mac);
                }
                break;
            case ETH_SRC:
                if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = match.getMasked(MatchField.ETH_SRC);
                    builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), MacAddress.valueOf(maskedMac.getMask().getLong()));
                } else {
                    mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
                    builder.matchEthSrc(mac);
                }
                break;
            case ETH_TYPE:
                int ethType = match.get(MatchField.ETH_TYPE).getValue();
                builder.matchEthType((short) ethType);
                break;
            case VLAN_VID:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                } else {
                    VlanId vlanId = null;
                    if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
                        Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
                        if (masked.getValue().equals(OFVlanVidMatch.PRESENT) && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
                            vlanId = VlanId.ANY;
                        }
                    } else {
                        if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
                            vlanId = VlanId.NONE;
                        } else {
                            vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
                        }
                    }
                    if (vlanId != null) {
                        builder.matchVlanId(vlanId);
                    }
                }
                break;
            case VLAN_PCP:
                byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
                builder.matchVlanPcp(vlanPcp);
                break;
            case IP_DSCP:
                byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
                builder.matchIPDscp(ipDscp);
                break;
            case IP_ECN:
                byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
                builder.matchIPEcn(ipEcn);
                break;
            case IP_PROTO:
                short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
                builder.matchIPProtocol((byte) proto);
                break;
            case IPV4_SRC:
                if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
                    Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
                    ip4Prefix = Ip4Prefix.valueOf(maskedIp.getValue().getInt(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip4Prefix = Ip4Prefix.valueOf(match.get(MatchField.IPV4_SRC).getInt(), Ip4Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPSrc(ip4Prefix);
                break;
            case IPV4_DST:
                if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
                    Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
                    ip4Prefix = Ip4Prefix.valueOf(maskedIp.getValue().getInt(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip4Prefix = Ip4Prefix.valueOf(match.get(MatchField.IPV4_DST).getInt(), Ip4Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPDst(ip4Prefix);
                break;
            case TCP_SRC:
                if (match.isPartiallyMasked(MatchField.TCP_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.TCP_SRC);
                    builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
                }
                break;
            case TCP_DST:
                if (match.isPartiallyMasked(MatchField.TCP_DST)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.TCP_DST);
                    builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
                }
                break;
            case UDP_SRC:
                if (match.isPartiallyMasked(MatchField.UDP_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.UDP_SRC);
                    builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
                }
                break;
            case UDP_DST:
                if (match.isPartiallyMasked(MatchField.UDP_DST)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.UDP_DST);
                    builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
                }
                break;
            case MPLS_LABEL:
                builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL).getValue()));
                break;
            case MPLS_BOS:
                builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
                break;
            case SCTP_SRC:
                if (match.isPartiallyMasked(MatchField.SCTP_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.SCTP_SRC);
                    builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
                }
                break;
            case SCTP_DST:
                if (match.isPartiallyMasked(MatchField.SCTP_DST)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.SCTP_DST);
                    builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
                }
                break;
            case ICMPV4_TYPE:
                byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
                builder.matchIcmpType(icmpType);
                break;
            case ICMPV4_CODE:
                byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
                builder.matchIcmpCode(icmpCode);
                break;
            case IPV6_SRC:
                if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
                    Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
                    ip6Prefix = Ip6Prefix.valueOf(maskedIp.getValue().getBytes(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip6Prefix = Ip6Prefix.valueOf(match.get(MatchField.IPV6_SRC).getBytes(), Ip6Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPv6Src(ip6Prefix);
                break;
            case IPV6_DST:
                if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
                    Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
                    ip6Prefix = Ip6Prefix.valueOf(maskedIp.getValue().getBytes(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip6Prefix = Ip6Prefix.valueOf(match.get(MatchField.IPV6_DST).getBytes(), Ip6Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPv6Dst(ip6Prefix);
                break;
            case IPV6_FLABEL:
                int flowLabel = match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
                builder.matchIPv6FlowLabel(flowLabel);
                break;
            case ICMPV6_TYPE:
                byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
                builder.matchIcmpv6Type(icmpv6type);
                break;
            case ICMPV6_CODE:
                byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
                builder.matchIcmpv6Code(icmpv6code);
                break;
            case IPV6_ND_TARGET:
                ip6Address = Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
                builder.matchIPv6NDTargetAddress(ip6Address);
                break;
            case IPV6_ND_SLL:
                mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
                builder.matchIPv6NDSourceLinkLayerAddress(mac);
                break;
            case IPV6_ND_TLL:
                mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
                builder.matchIPv6NDTargetLinkLayerAddress(mac);
                break;
            case IPV6_EXTHDR:
                builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR).getValue());
                break;
            case OCH_SIGID:
                CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
                builder.add(matchLambda(Lambda.ochSignal(lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()), sigId.getChannelNumber(), sigId.getSpectralWidth())));
                break;
            case OCH_SIGTYPE:
                U8 sigType = match.get(MatchField.OCH_SIGTYPE);
                builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
                break;
            case EXP_OCH_SIG_ID:
                try {
                    CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
                    builder.add(matchLambda(Lambda.ochSignal(lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()), expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                    break;
                }
                break;
            case EXP_OCH_SIGTYPE:
                try {
                    U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
                    builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                    break;
                }
                break;
            case EXP_ODU_SIG_ID:
                OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(), match.get(MatchField.EXP_ODU_SIG_ID).getTslen(), match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
                builder.add(matchOduSignalId(oduSignalId));
                break;
            case EXP_ODU_SIGTYPE:
                try {
                    U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
                    builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                    break;
                }
                break;
            case TUNNEL_ID:
                long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
                builder.matchTunnelId(tunnelId);
                break;
            case ARP_OP:
                int arpOp = match.get(MatchField.ARP_OP).getOpcode();
                builder.matchArpOp(arpOp);
                break;
            case ARP_SHA:
                mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
                builder.matchArpSha(mac);
                break;
            case ARP_SPA:
                ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
                builder.matchArpSpa(ip);
                break;
            case ARP_THA:
                mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
                builder.matchArpTha(mac);
                break;
            case ARP_TPA:
                ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
                builder.matchArpTpa(ip);
                break;
            case NSP:
                if (selectorInterpreter != null) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case NSI:
                if (selectorInterpreter != null) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case ENCAP_ETH_TYPE:
                if (selectorInterpreter != null) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case CONNTRACK_STATE:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case CONNTRACK_ZONE:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case CONNTRACK_MARK:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case OFDPA_OVID:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case OFDPA_MPLS_L2_PORT:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case OFDPA_ALLOW_VLAN_TRANSLATION:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ALLOW_VLAN_TRANSLATION);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case OFDPA_ACTSET_OUTPUT:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ACTSET_OUTPUT);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case MPLS_TC:
            default:
                log.warn("Match type {} not yet implemented.", field.id);
        }
    }
    return builder.build();
}
Also used : U8(org.projectfloodlight.openflow.types.U8) Ip4Address(org.onlab.packet.Ip4Address) IPv6Address(org.projectfloodlight.openflow.types.IPv6Address) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) Ip6Prefix(org.onlab.packet.Ip6Prefix) Ip6Address(org.onlab.packet.Ip6Address) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OduSignalId(org.onosproject.net.OduSignalId) Instructions.modL1OduSignalId(org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId) TransportPort(org.projectfloodlight.openflow.types.TransportPort) VlanId(org.onlab.packet.VlanId) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) CircuitSignalID(org.projectfloodlight.openflow.types.CircuitSignalID) MacAddress(org.onlab.packet.MacAddress) ExtensionSelectorInterpreter(org.onosproject.openflow.controller.ExtensionSelectorInterpreter) OFOxm(org.projectfloodlight.openflow.protocol.oxm.OFOxm) Ip4Prefix(org.onlab.packet.Ip4Prefix)

Example 40 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class GroupModBuilder method buildL3Modification.

private OFAction buildL3Modification(Instruction i) {
    L3ModificationInstruction l3m = (L3ModificationInstruction) i;
    L3ModificationInstruction.ModIPInstruction ip;
    Ip4Address ip4;
    Ip6Address ip6;
    OFOxm<?> oxm = null;
    switch(l3m.subtype()) {
        case IPV4_SRC:
            ip = (L3ModificationInstruction.ModIPInstruction) i;
            ip4 = ip.ip().getIp4Address();
            oxm = factory.oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
            break;
        case IPV4_DST:
            ip = (L3ModificationInstruction.ModIPInstruction) i;
            ip4 = ip.ip().getIp4Address();
            oxm = factory.oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
            break;
        case IPV6_SRC:
            ip = (L3ModificationInstruction.ModIPInstruction) i;
            ip6 = ip.ip().getIp6Address();
            oxm = factory.oxms().ipv6Src(IPv6Address.of(ip6.toOctets()));
            break;
        case IPV6_DST:
            ip = (L3ModificationInstruction.ModIPInstruction) i;
            ip6 = ip.ip().getIp6Address();
            oxm = factory.oxms().ipv6Dst(IPv6Address.of(ip6.toOctets()));
            break;
        case IPV6_FLABEL:
            L3ModificationInstruction.ModIPv6FlowLabelInstruction flowLabelInstruction = (L3ModificationInstruction.ModIPv6FlowLabelInstruction) i;
            int flowLabel = flowLabelInstruction.flowLabel();
            oxm = factory.oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel));
            break;
        case DEC_TTL:
            return factory.actions().decNwTtl();
        case TTL_IN:
            return factory.actions().copyTtlIn();
        case TTL_OUT:
            return factory.actions().copyTtlOut();
        default:
            log.warn("Unimplemented action type {}.", l3m.subtype());
            break;
    }
    if (oxm != null) {
        return factory.actions().buildSetField().setField(oxm).build();
    }
    return null;
}
Also used : L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address)

Aggregations

Ip4Address (org.onlab.packet.Ip4Address)98 Test (org.junit.Test)29 Ip4Prefix (org.onlab.packet.Ip4Prefix)20 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)15 MacAddress (org.onlab.packet.MacAddress)15 ArrayList (java.util.ArrayList)14 Ip6Address (org.onlab.packet.Ip6Address)14 IpAddress (org.onlab.packet.IpAddress)13 LinkedList (java.util.LinkedList)12 Ethernet (org.onlab.packet.Ethernet)12 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)12 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)12 AsPath (org.onosproject.bgpio.types.AsPath)12 BgpHeader (org.onosproject.bgpio.types.BgpHeader)12 BgpValueType (org.onosproject.bgpio.types.BgpValueType)12 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)12 Med (org.onosproject.bgpio.types.Med)12 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)12 Origin (org.onosproject.bgpio.types.Origin)12 OriginType (org.onosproject.bgpio.types.Origin.OriginType)12