Ejemplo n.º 1
0
 @Override
 public InboundPacket inPacket() {
   IPv6 ipv6 = new IPv6();
   ipv6.setDestinationAddress(Ip6Address.valueOf("1000::1").toOctets());
   ipv6.setSourceAddress(IP2);
   Ethernet eth = new Ethernet();
   eth.setEtherType(Ethernet.TYPE_IPV6)
       .setVlanID(VLAN.toShort())
       .setSourceMACAddress(MAC2)
       .setDestinationMACAddress(MacAddress.valueOf("00:00:00:00:00:01"))
       .setPayload(ipv6);
   ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), portNumber(INPORT));
   return new DefaultInboundPacket(receivedFrom, eth, ByteBuffer.wrap(eth.serialize()));
 }
Ejemplo n.º 2
0
 @Override
 public InboundPacket inPacket() {
   RouterSolicitation ns = new RouterSolicitation();
   ICMP6 icmp6 = new ICMP6();
   icmp6.setPayload(ns);
   IPv6 ipv6 = new IPv6();
   ipv6.setPayload(icmp6);
   ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::2").toOctets());
   ipv6.setSourceAddress(Ip6Address.valueOf("::").toOctets());
   Ethernet eth = new Ethernet();
   eth.setEtherType(Ethernet.TYPE_IPV6)
       .setVlanID(VLAN.toShort())
       .setSourceMACAddress(MAC2.toBytes())
       .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:02"))
       .setPayload(ipv6);
   ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), portNumber(INPORT));
   return new DefaultInboundPacket(receivedFrom, eth, ByteBuffer.wrap(eth.serialize()));
 }
Ejemplo n.º 3
0
 @Override
 public InboundPacket inPacket() {
   NeighborAdvertisement na = new NeighborAdvertisement();
   ICMP6 icmp6 = new ICMP6();
   icmp6.setPayload(na);
   IPv6 ipv6 = new IPv6();
   ipv6.setPayload(icmp6);
   ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
   ipv6.setSourceAddress(IP2);
   Ethernet eth = new Ethernet();
   eth.setEtherType(Ethernet.TYPE_IPV6)
       .setVlanID(VLAN.toShort())
       .setSourceMACAddress(MAC2.toBytes())
       .setDestinationMACAddress(BCMAC2)
       .setPayload(ipv6);
   ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), portNumber(INPORT));
   return new DefaultInboundPacket(receivedFrom, eth, ByteBuffer.wrap(eth.serialize()));
 }
Ejemplo n.º 4
0
  private Ethernet buildNdpRequest(
      IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) {

    // Create the Ethernet packet
    Ethernet ethernet = new Ethernet();
    ethernet
        .setEtherType(Ethernet.TYPE_IPV6)
        .setDestinationMACAddress(MacAddress.BROADCAST)
        .setSourceMACAddress(sourceMac);
    if (!vlan.equals(VlanId.NONE)) {
      ethernet.setVlanID(vlan.toShort());
    }

    //
    // Create the IPv6 packet
    //
    // TODO: The destination IP address should be the
    // solicited-node multicast address
    IPv6 ipv6 = new IPv6();
    ipv6.setSourceAddress(sourceIp.toOctets());
    ipv6.setDestinationAddress(targetIp.toOctets());
    ipv6.setHopLimit((byte) 255);

    // Create the ICMPv6 packet
    ICMP6 icmp6 = new ICMP6();
    icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION);
    icmp6.setIcmpCode((byte) 0);

    // Create the Neighbor Solication packet
    NeighborSolicitation ns = new NeighborSolicitation();
    ns.setTargetAddress(targetIp.toOctets());
    ns.addOption(NeighborDiscoveryOptions.TYPE_SOURCE_LL_ADDRESS, sourceMac.toBytes());

    icmp6.setPayload(ns);
    ipv6.setPayload(icmp6);
    ethernet.setPayload(ipv6);

    return ethernet;
  }
  // Install a rule forwarding the packet to the specified port.
  private void installRule(PacketContext context, PortNumber portNumber) {
    //
    // We don't support (yet) buffer IDs in the Flow Service so
    // packet out first.
    //
    Ethernet inPkt = context.inPacket().parsed();
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();

    // If PacketOutOnly or ARP packet than forward directly to output port
    if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) {
      packetOut(context, portNumber);
      return;
    }

    //
    // If matchDstMacOnly
    //    Create flows matching dstMac only
    // Else
    //    Create flows with default matching and include configured fields
    //
    if (matchDstMacOnly) {
      selectorBuilder.matchEthDst(inPkt.getDestinationMAC());
    } else {
      selectorBuilder
          .matchInPort(context.inPacket().receivedFrom().port())
          .matchEthSrc(inPkt.getSourceMAC())
          .matchEthDst(inPkt.getDestinationMAC());

      // If configured Match Vlan ID
      if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
        selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID()));
      }

      //
      // If configured and EtherType is IPv4 - Match IPv4 and
      // TCP/UDP/ICMP fields
      //
      if (matchIpv4Address && inPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) inPkt.getPayload();
        byte ipv4Protocol = ipv4Packet.getProtocol();
        Ip4Prefix matchIp4SrcPrefix =
            Ip4Prefix.valueOf(ipv4Packet.getSourceAddress(), Ip4Prefix.MAX_MASK_LENGTH);
        Ip4Prefix matchIp4DstPrefix =
            Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), Ip4Prefix.MAX_MASK_LENGTH);
        selectorBuilder
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPSrc(matchIp4SrcPrefix)
            .matchIPDst(matchIp4DstPrefix);

        if (matchIpv4Dscp) {
          byte dscp = ipv4Packet.getDscp();
          byte ecn = ipv4Packet.getEcn();
          selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn);
        }

        if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) {
          TCP tcpPacket = (TCP) ipv4Packet.getPayload();
          selectorBuilder
              .matchIPProtocol(ipv4Protocol)
              .matchTcpSrc(tcpPacket.getSourcePort())
              .matchTcpDst(tcpPacket.getDestinationPort());
        }
        if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) {
          UDP udpPacket = (UDP) ipv4Packet.getPayload();
          selectorBuilder
              .matchIPProtocol(ipv4Protocol)
              .matchUdpSrc(udpPacket.getSourcePort())
              .matchUdpDst(udpPacket.getDestinationPort());
        }
        if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) {
          ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
          selectorBuilder
              .matchIPProtocol(ipv4Protocol)
              .matchIcmpType(icmpPacket.getIcmpType())
              .matchIcmpCode(icmpPacket.getIcmpCode());
        }
      }

      //
      // If configured and EtherType is IPv6 - Match IPv6 and
      // TCP/UDP/ICMP fields
      //
      if (matchIpv6Address && inPkt.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) inPkt.getPayload();
        byte ipv6NextHeader = ipv6Packet.getNextHeader();
        Ip6Prefix matchIp6SrcPrefix =
            Ip6Prefix.valueOf(ipv6Packet.getSourceAddress(), Ip6Prefix.MAX_MASK_LENGTH);
        Ip6Prefix matchIp6DstPrefix =
            Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), Ip6Prefix.MAX_MASK_LENGTH);
        selectorBuilder
            .matchEthType(Ethernet.TYPE_IPV6)
            .matchIPv6Src(matchIp6SrcPrefix)
            .matchIPv6Dst(matchIp6DstPrefix);

        if (matchIpv6FlowLabel) {
          selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel());
        }

        if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) {
          TCP tcpPacket = (TCP) ipv6Packet.getPayload();
          selectorBuilder
              .matchIPProtocol(ipv6NextHeader)
              .matchTcpSrc(tcpPacket.getSourcePort())
              .matchTcpDst(tcpPacket.getDestinationPort());
        }
        if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) {
          UDP udpPacket = (UDP) ipv6Packet.getPayload();
          selectorBuilder
              .matchIPProtocol(ipv6NextHeader)
              .matchUdpSrc(udpPacket.getSourcePort())
              .matchUdpDst(udpPacket.getDestinationPort());
        }
        if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) {
          ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
          selectorBuilder
              .matchIPProtocol(ipv6NextHeader)
              .matchIcmpv6Type(icmp6Packet.getIcmpType())
              .matchIcmpv6Code(icmp6Packet.getIcmpCode());
        }
      }
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(portNumber).build();

    ForwardingObjective forwardingObjective =
        DefaultForwardingObjective.builder()
            .withSelector(selectorBuilder.build())
            .withTreatment(treatment)
            .withPriority(flowPriority)
            .withFlag(ForwardingObjective.Flag.VERSATILE)
            .fromApp(appId)
            .makeTemporary(flowTimeout)
            .add();

    flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), forwardingObjective);

    //
    // If packetOutOfppTable
    //  Send packet back to the OpenFlow pipeline to match installed flow
    // Else
    //  Send packet direction on the appropriate port
    //
    if (packetOutOfppTable) {
      packetOut(context, PortNumber.TABLE);
    } else {
      packetOut(context, portNumber);
    }
  }
Ejemplo n.º 6
0
    @Override
    public void process(PacketContext context) {
      if (context == null) {
        return;
      }
      Ethernet eth = context.inPacket().parsed();

      if (eth == null) {
        return;
      }

      VlanId vlan = VlanId.vlanId(eth.getVlanID());
      ConnectPoint heardOn = context.inPacket().receivedFrom();

      // If this is not an edge port, bail out.
      Topology topology = topologyService.currentTopology();
      if (topologyService.isInfrastructure(topology, heardOn)) {
        return;
      }

      HostLocation hloc = new HostLocation(heardOn, System.currentTimeMillis());

      HostId hid = HostId.hostId(eth.getSourceMAC(), vlan);

      // ARP: possible new hosts, update both location and IP
      if (eth.getEtherType() == Ethernet.TYPE_ARP) {
        ARP arp = (ARP) eth.getPayload();
        IpAddress ip = IpAddress.valueOf(IpAddress.Version.INET, arp.getSenderProtocolAddress());
        HostDescription hdescr = new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip);
        providerService.hostDetected(hid, hdescr);

        // IPv4: update location only
      } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) {
        HostDescription hdescr = new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc);
        providerService.hostDetected(hid, hdescr);

        // NeighborAdvertisement and NeighborSolicitation: possible new hosts, update both location
        // and IP
        // IPv6: update location only
      } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IpAddress ip = null;
        IPv6 ipv6 = (IPv6) eth.getPayload();

        IPacket iPkt = ipv6;
        while (iPkt != null) {
          if (iPkt instanceof NeighborAdvertisement || iPkt instanceof NeighborSolicitation) {
            IpAddress sourceAddress =
                IpAddress.valueOf(IpAddress.Version.INET6, ipv6.getSourceAddress());
            // Ignore DAD packets, in which source address is all zeros.
            if (!sourceAddress.isZero()) {
              ip = sourceAddress;
              break;
            }
          }
          iPkt = iPkt.getPayload();
        }
        HostDescription hdescr =
            (ip == null)
                ? new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc)
                : new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip);
        providerService.hostDetected(hid, hdescr);
      }
    }