示例#1
0
  @Test
  public void testTpDst_upperPorts() {
    pktCtx.wcmatch().setDstPort(50000);

    Condition cond = new Condition();
    pktCtx.inPortId_$eq(UUID.randomUUID());
    Assert.assertTrue(cond.matches(pktCtx));
    cond.tpDst = new Range<>(40000, Transport.MAX_PORT_NO);
    Assert.assertTrue(cond.matches(pktCtx));
    cond.tpDstInv = true;
    Assert.assertFalse(cond.matches(pktCtx));
    cond.tpDstInv = false;
    Assert.assertTrue(cond.matches(pktCtx));
    cond.tpDst = new Range<>(55000, Transport.MAX_PORT_NO);
    Assert.assertFalse(cond.matches(pktCtx));
    cond.tpDstInv = true;
    Assert.assertTrue(cond.matches(pktCtx));
    cond.tpDstInv = false;
    Assert.assertFalse(cond.matches(pktCtx));
    cond.tpDst = new Range<>(45000, 55000);
    Assert.assertTrue(cond.matches(pktCtx));
    cond.tpDstInv = true;
    Assert.assertFalse(cond.matches(pktCtx));
    cond.tpDstInv = false;
    cond.tpDst = new Range<>(0, Transport.MAX_PORT_NO);
    Assert.assertTrue(cond.matches(pktCtx));
  }
示例#2
0
 @Test
 public void testTpDst() {
   // tpDst is set to 1234
   Condition cond = new Condition();
   pktCtx.inPortId_$eq(UUID.randomUUID());
   Assert.assertTrue(cond.matches(pktCtx));
   cond.tpDst = new Range<>(1235, Transport.MAX_PORT_NO);
   Assert.assertFalse(cond.matches(pktCtx));
   cond.tpDstInv = true;
   Assert.assertTrue(cond.matches(pktCtx));
   cond.tpDstInv = false;
   cond.tpDst = new Range<>(1233, Transport.MAX_PORT_NO);
   Assert.assertTrue(cond.matches(pktCtx));
   cond.tpDstInv = true;
   Assert.assertFalse(cond.matches(pktCtx));
   cond.tpDstInv = false;
   cond.tpDst = new Range<>(1233, 1233);
   Assert.assertFalse(cond.matches(pktCtx));
   cond.tpDst = new Range<>(1233, 1234);
   Assert.assertTrue(cond.matches(pktCtx));
   cond.tpDstInv = true;
   Assert.assertFalse(cond.matches(pktCtx));
   cond.tpDstInv = false;
   cond.tpDst = new Range<>(0, 1234);
   Assert.assertTrue(cond.matches(pktCtx));
 }
示例#3
0
  @Test
  public void testSerialization() throws IOException, ClassNotFoundException {
    Condition cond = new Condition();
    Set<UUID> ids = new HashSet<>();
    ids.add(UUID.randomUUID());
    ids.add(UUID.randomUUID());
    cond.inPortIds = ids;
    cond.portGroup = UUID.randomUUID();
    cond.tpSrc = new Range<>(40000, 41000);
    cond.tpSrcInv = false;
    cond.tpDst = new Range<>(42000, 43000);
    cond.tpDstInv = true;
    cond.etherType = 0x86DD;

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    OutputStream out = new BufferedOutputStream(bos);
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(new OutputStreamWriter(out));
    jsonGenerator.writeObject(cond);
    out.close();
    byte[] data = bos.toByteArray();
    ByteArrayInputStream bis = new ByteArrayInputStream(data);
    InputStream in = new BufferedInputStream(bis);
    JsonParser jsonParser = jsonFactory.createJsonParser(new InputStreamReader(in));
    Condition c = jsonParser.readValueAs(Condition.class);
    in.close();
    Assert.assertTrue(cond.equals(c));
  }