Пример #1
0
  // Create a RecordsKeys "shrink" instance path from an InstanceIdentifier
  public static RecordKeys getIdentifiableItemID(IdentifiableItem<?, Identifier<?>> ia) {
    RecordKeysBuilder rec = new RecordKeysBuilder();
    rec.setKeyName(ia.getType().getSimpleName());

    if (ia.getKey() instanceof MeterKey) {
      MeterKey mk = (MeterKey) ia.getKey();
      rec.setKeyValue("" + mk.getMeterId().getValue());
    } else if (ia.getKey() instanceof FlowKey) {
      FlowKey flowKey = (FlowKey) ia.getKey();
      rec.setKeyValue("" + flowKey.getId().getValue());
    } else if (ia.getKey() instanceof QueueKey) {
      QueueKey qk = (QueueKey) ia.getKey();
      rec.setKeyValue("" + qk.getQueueId().getValue());
    } else if (ia.getKey() instanceof GroupKey) {
      GroupKey gk = (GroupKey) ia.getKey();
      rec.setKeyValue("" + gk.getGroupId().getValue());
    } else if (ia.getKey() instanceof NodeConnectorKey) {
      NodeConnectorKey nck = (NodeConnectorKey) ia.getKey();
      rec.setKeyValue(nck.getId().getValue());
    } else if (ia.getKey() instanceof NodeKey) {
      NodeKey nk = (NodeKey) ia.getKey();
      rec.setKeyValue(nk.getId().getValue());
    } else if (ia.getKey() instanceof TableKey) {
      TableKey tk = (TableKey) ia.getKey();
      rec.setKeyValue("" + tk.getId());
    } else {
      throw new IllegalArgumentException(
          "Unknown DataObject Key of type " + ia.getType().getName());
    }
    return rec.build();
  }
 private static PortNumber getPortNumber(final PathArgument pathArgument, final Short ofVersion) {
   // FIXME VD P! find InstanceIdentifier helper
   InstanceIdentifier.IdentifiableItem<?, ?> item =
       Arguments.checkInstanceOf(pathArgument, InstanceIdentifier.IdentifiableItem.class);
   NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class);
   String[] split = key.getId().getValue().split(":");
   Long port =
       OpenflowPortsUtil.getPortFromLogicalName(
           OpenflowVersion.get(ofVersion), split[split.length - 1]);
   return new PortNumber(port);
 }