@Override
 public OpenFlowSwitch getSwitch(Dpid dpid) {
   if (dpid.equals(Dpid.dpid(DID.uri()))) {
     current = sw;
   } else {
     current = null;
   }
   return current;
 }
예제 #2
0
  @Override
  public void emit(OutboundPacket packet) {
    DeviceId devId = packet.sendThrough();
    String scheme = devId.toString().split(":")[0];

    if (!scheme.equals(this.id().scheme())) {
      throw new IllegalArgumentException("Don't know how to handle Device with scheme " + scheme);
    }

    Dpid dpid = Dpid.dpid(devId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null) {
      log.warn("Device {} isn't available?", devId);
      return;
    }

    // Ethernet eth = new Ethernet();
    // eth.deserialize(packet.data().array(), 0, packet.data().array().length);
    OFPortDesc p = null;
    for (Instruction inst : packet.treatment().allInstructions()) {
      if (inst.type().equals(Instruction.Type.OUTPUT)) {
        p = portDesc(((OutputInstruction) inst).port());
        OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo());
        sw.sendMsg(po);
      }
    }
  }
예제 #3
0
    @Override
    public void handlePacket(OpenFlowPacketContext pktCtx) {
      DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value()));

      DefaultInboundPacket inPkt =
          new DefaultInboundPacket(
              new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())),
              pktCtx.parsed(),
              ByteBuffer.wrap(pktCtx.unparsed()));

      DefaultOutboundPacket outPkt = null;
      if (!pktCtx.isBuffered()) {
        outPkt = new DefaultOutboundPacket(id, null, ByteBuffer.wrap(pktCtx.unparsed()));
      }

      OpenFlowCorePacketContext corePktCtx =
          new OpenFlowCorePacketContext(
              System.currentTimeMillis(), inPkt, outPkt, pktCtx.isHandled(), pktCtx);
      providerService.processPacket(corePktCtx);
    }