@SuppressWarnings("unchecked") public void serializeAttributes(Map<Object, Object> attributes, JsonGenerator jGen) throws IOException, JsonProcessingException { if ( null == attributes) jGen.writeStringField("attributes","null"); else{ jGen.writeFieldName("attributes"); jGen.writeStartObject(); for (Map.Entry<Object, Object> entry : attributes.entrySet()) { if( entry.getValue() instanceof EnumSet<?>){ jGen.writeFieldName(entry.getKey().toString()); jGen.writeStartArray(); //Maybe need to check other type. for(OFFlowWildcards wildcard : (EnumSet<OFFlowWildcards>)entry.getValue()){ jGen.writeString(wildcard.toString()); } jGen.writeEndArray(); } else jGen.writeStringField(entry.getKey().toString(),entry.getValue().toString()); } jGen.writeEndObject(); } }
public OFSwitch(IOFConnectionBackend connection, @Nonnull OFFactory factory, @Nonnull IOFSwitchManager switchManager, @Nonnull DatapathId datapathId) { if(connection == null) throw new NullPointerException("connection must not be null"); if(!connection.getAuxId().equals(OFAuxId.MAIN)) throw new IllegalArgumentException("connection must be the main connection"); if(factory == null) throw new NullPointerException("factory must not be null"); if(switchManager == null) throw new NullPointerException("switchManager must not be null"); this.connected = true; this.factory = factory; this.switchManager = switchManager; this.datapathId = datapathId; this.attributes = new ConcurrentHashMap<Object, Object>(); this.role = null; this.description = new SwitchDescription(); this.portManager = new PortManager(); this.status = SwitchStatus.HANDSHAKE; // Connections this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.connections.put(connection.getAuxId(), connection); // Switch's controller connection this.controllerConnections = ImmutableMap.of(); // Defaults properties for an ideal switch this.setAttribute(PROP_FASTWILDCARDS, EnumSet.allOf(OFFlowWildcards.class)); this.setAttribute(PROP_SUPPORTS_OFPP_FLOOD, Boolean.TRUE); this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, Boolean.TRUE); this.tableFeaturesByTableId = new HashMap<TableId, TableFeatures>(); this.tables = new ArrayList<TableId>(); this.securityKernel = switchManager.getSecurityKernelService(); }
public OFSwitch(IOFConnectionBackend connection, @Nonnull OFFactory factory, @Nonnull IOFSwitchManager switchManager, @Nonnull DatapathId datapathId) { if(connection == null) throw new NullPointerException("connection must not be null"); if(!connection.getAuxId().equals(OFAuxId.MAIN)) throw new IllegalArgumentException("connection must be the main connection"); if(factory == null) throw new NullPointerException("factory must not be null"); if(switchManager == null) throw new NullPointerException("switchManager must not be null"); this.connected = true; this.factory = factory; this.switchManager = switchManager; this.datapathId = datapathId; this.attributes = new ConcurrentHashMap<Object, Object>(); this.role = null; this.description = new SwitchDescription(); this.portManager = new PortManager(); this.status = SwitchStatus.HANDSHAKE; // Connections this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.connections.put(connection.getAuxId(), connection); // Switch's controller connection this.controllerConnections = ImmutableMap.of(); // Defaults properties for an ideal switch this.setAttribute(PROP_FASTWILDCARDS, EnumSet.allOf(OFFlowWildcards.class)); this.setAttribute(PROP_SUPPORTS_OFPP_FLOOD, Boolean.TRUE); this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, Boolean.TRUE); }
public OFSwitch(IOFConnectionBackend connection, @Nonnull OFFactory factory, @Nonnull IOFSwitchManager switchManager, @Nonnull DatapathId datapathId) { if(connection == null) throw new NullPointerException("connection must not be null"); if(!connection.getAuxId().equals(OFAuxId.MAIN)) throw new IllegalArgumentException("connection must be the main connection"); if(factory == null) throw new NullPointerException("factory must not be null"); if(switchManager == null) throw new NullPointerException("switchManager must not be null"); this.connected = true; this.factory = factory; this.switchManager = switchManager; this.datapathId = datapathId; this.attributes = new ConcurrentHashMap<Object, Object>(); this.role = null; this.description = new SwitchDescription(); this.portManager = new PortManager(); this.status = SwitchStatus.HANDSHAKE; // Connections this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.connections.put(connection.getAuxId(), connection); // Switch's controller connection this.controllerConnections = ImmutableMap.of(); // Defaults properties for an ideal switch this.setAttribute(PROP_FASTWILDCARDS, EnumSet.allOf(OFFlowWildcards.class)); this.setAttribute(PROP_SUPPORTS_OFPP_FLOOD, Boolean.TRUE); this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, Boolean.TRUE); this.tableFeaturesByTableId = new HashMap<TableId, TableFeatures>(); this.tables = new ArrayList<TableId>(); }
public OFSwitch(IOFConnectionBackend connection, @Nonnull OFFactory factory, @Nonnull IOFSwitchManager switchManager, @Nonnull DatapathId datapathId) { if(connection == null) throw new NullPointerException("connection must not be null"); if(!connection.getAuxId().equals(OFAuxId.MAIN)) throw new IllegalArgumentException("connection must be the main connection"); if(factory == null) throw new NullPointerException("factory must not be null"); if(switchManager == null) throw new NullPointerException("switchManager must not be null"); this.connected = true; this.factory = factory; this.switchManager = switchManager; this.datapathId = datapathId; this.attributes = new ConcurrentHashMap<Object, Object>(); this.role = null; this.description = new SwitchDescription(); this.portManager = new PortManager(); this.status = SwitchStatus.HANDSHAKE; // Connections this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.connections.put(connection.getAuxId(), connection); // Switch's controller connection this.controllerConnections = ImmutableMap.of(); // Defaults properties for an ideal switch this.setAttribute(PROP_FASTWILDCARDS, EnumSet.allOf(OFFlowWildcards.class)); this.setAttribute(PROP_SUPPORTS_OFPP_FLOOD, Boolean.TRUE); this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, Boolean.TRUE); this.tableFeaturesByTableId = new HashMap<TableId, TableFeatures>(); }
public static Set<OFFlowWildcards> readFrom(ChannelBuffer bb) throws OFParseError { try { return ofWireValue(bb.readInt()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
public static Set<OFFlowWildcards> ofWireValue(int val) { EnumSet<OFFlowWildcards> set = EnumSet.noneOf(OFFlowWildcards.class); if((val & IN_PORT_VAL) != 0) set.add(OFFlowWildcards.IN_PORT); if((val & DL_VLAN_VAL) != 0) set.add(OFFlowWildcards.DL_VLAN); if((val & DL_SRC_VAL) != 0) set.add(OFFlowWildcards.DL_SRC); if((val & DL_DST_VAL) != 0) set.add(OFFlowWildcards.DL_DST); if((val & DL_TYPE_VAL) != 0) set.add(OFFlowWildcards.DL_TYPE); if((val & NW_PROTO_VAL) != 0) set.add(OFFlowWildcards.NW_PROTO); if((val & TP_SRC_VAL) != 0) set.add(OFFlowWildcards.TP_SRC); if((val & TP_DST_VAL) != 0) set.add(OFFlowWildcards.TP_DST); if((val & NW_SRC_ALL_VAL) != 0) set.add(OFFlowWildcards.NW_SRC_ALL); if((val & NW_SRC_MASK_VAL) != 0) set.add(OFFlowWildcards.NW_SRC_MASK); if((val & NW_DST_ALL_VAL) != 0) set.add(OFFlowWildcards.NW_DST_ALL); if((val & NW_DST_MASK_VAL) != 0) set.add(OFFlowWildcards.NW_DST_MASK); if((val & DL_VLAN_PCP_VAL) != 0) set.add(OFFlowWildcards.DL_VLAN_PCP); if((val & NW_TOS_VAL) != 0) set.add(OFFlowWildcards.NW_TOS); if((val & ALL_VAL) != 0) set.add(OFFlowWildcards.ALL); return Collections.unmodifiableSet(set); }
public static Set<OFFlowWildcards> ofWireValue(int val) { EnumSet<OFFlowWildcards> set = EnumSet.noneOf(OFFlowWildcards.class); if((val & IN_PORT_VAL) != 0) set.add(OFFlowWildcards.IN_PORT); if((val & DL_VLAN_VAL) != 0) set.add(OFFlowWildcards.DL_VLAN); if((val & DL_TYPE_VAL) != 0) set.add(OFFlowWildcards.DL_TYPE); if((val & NW_PROTO_VAL) != 0) set.add(OFFlowWildcards.NW_PROTO); if((val & TP_SRC_VAL) != 0) set.add(OFFlowWildcards.TP_SRC); if((val & TP_DST_VAL) != 0) set.add(OFFlowWildcards.TP_DST); if((val & DL_VLAN_PCP_VAL) != 0) set.add(OFFlowWildcards.DL_VLAN_PCP); if((val & NW_TOS_VAL) != 0) set.add(OFFlowWildcards.NW_TOS); if((val & ALL_VAL) != 0) set.add(OFFlowWildcards.ALL); if((val & MPLS_LABEL_VAL) != 0) set.add(OFFlowWildcards.MPLS_LABEL); if((val & MPLS_TC_VAL) != 0) set.add(OFFlowWildcards.MPLS_TC); return Collections.unmodifiableSet(set); }
public static Set<OFFlowWildcards> readFrom(ByteBuf bb) throws OFParseError { try { return ofWireValue(bb.readInt()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
public static void writeTo(ChannelBuffer bb, Set<OFFlowWildcards> set) { bb.writeInt(toWireValue(set)); }
public static void putTo(Set<OFFlowWildcards> set, PrimitiveSink sink) { sink.putInt(toWireValue(set)); }
public static int toWireValue(Set<OFFlowWildcards> set) { int wireValue = 0; for(OFFlowWildcards e: set) { switch(e) { case IN_PORT: wireValue |= IN_PORT_VAL; break; case DL_VLAN: wireValue |= DL_VLAN_VAL; break; case DL_SRC: wireValue |= DL_SRC_VAL; break; case DL_DST: wireValue |= DL_DST_VAL; break; case DL_TYPE: wireValue |= DL_TYPE_VAL; break; case NW_PROTO: wireValue |= NW_PROTO_VAL; break; case TP_SRC: wireValue |= TP_SRC_VAL; break; case TP_DST: wireValue |= TP_DST_VAL; break; case NW_SRC_ALL: wireValue |= NW_SRC_ALL_VAL; break; case NW_SRC_MASK: wireValue |= NW_SRC_MASK_VAL; break; case NW_DST_ALL: wireValue |= NW_DST_ALL_VAL; break; case NW_DST_MASK: wireValue |= NW_DST_MASK_VAL; break; case DL_VLAN_PCP: wireValue |= DL_VLAN_PCP_VAL; break; case NW_TOS: wireValue |= NW_TOS_VAL; break; case ALL: wireValue |= ALL_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFFlowWildcards in version 1.0: " + e); } } return wireValue; }
public static int toWireValue(Set<OFFlowWildcards> set) { int wireValue = 0; for(OFFlowWildcards e: set) { switch(e) { case IN_PORT: wireValue |= IN_PORT_VAL; break; case DL_VLAN: wireValue |= DL_VLAN_VAL; break; case DL_TYPE: wireValue |= DL_TYPE_VAL; break; case NW_PROTO: wireValue |= NW_PROTO_VAL; break; case TP_SRC: wireValue |= TP_SRC_VAL; break; case TP_DST: wireValue |= TP_DST_VAL; break; case DL_VLAN_PCP: wireValue |= DL_VLAN_PCP_VAL; break; case NW_TOS: wireValue |= NW_TOS_VAL; break; case ALL: wireValue |= ALL_VAL; break; case MPLS_LABEL: wireValue |= MPLS_LABEL_VAL; break; case MPLS_TC: wireValue |= MPLS_TC_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFFlowWildcards in version 1.1: " + e); } } return wireValue; }
public static void writeTo(ByteBuf bb, Set<OFFlowWildcards> set) { bb.writeInt(toWireValue(set)); }